Giter VIP home page Giter VIP logo

Comments (5)

kevinansfield avatar kevinansfield commented on July 28, 2024 2

The content-api.js and the content-api.min.js are not being transpiled to es5.

cjs/content-api.js should not be transpiled to es5 as it's a node.js build.

umd/content-api.min.js should definitely be transpiled and have polyfills bundled as that is intended as a standalone browser build for use with <script src="https://unpkg.com/@tryghost/[email protected]/umd/content-api.min.js">. Thanks for pointing out the bug!

If you're pulling this module into a webpack build it will actually look at the module value in package.json and then use the lib/index.js code which is the source code. It was my assumption that webpack would automatically transpile that code based on your app's configured targets but it appears I was too optimistic about the current state of various bundler environments 😞

I've updated our rollup config across our isomorphic packages so that we generate an es/{package}.js file as the "module" build that webpack will use. This build will include transpilation back to the default browser support of @babel/preset-env as well as inclusion of any necessary polyfills. Unfortunately this will result in larger builds but I can't see a way around that, if a module consumer really wants to shave off some bytes it will be up to them to reference the lib/* files with appropriate transpilation in their build config.

Please try upgrading to the new 1.2.0 version and let me know how it goes πŸ˜„

from sdk.

rsarai avatar rsarai commented on July 28, 2024 1

Thanks @kevinansfield, it worked!

from sdk.

kevinansfield avatar kevinansfield commented on July 28, 2024

Import on your project import GhostContentAPI from '@tryghost/content-api';

How are you doing the import and resulting transpilation? The ES module version of the library is written with ES6 so it's expected that it will be transpiled with babel etc to work with your chosen browser/environment targets.

from sdk.

rsarai avatar rsarai commented on July 28, 2024

@kevinansfield Thanks for the prompt response!

Answering your question I have a react application using webpack and babel.

One other thing I realized was that on my node_modules I have this folder:
image

The content-api.js and the content-api.min.js are not being transpiled to es5. Do you have any insights that can help me?

from sdk.

rsarai avatar rsarai commented on July 28, 2024

Yep, the code is not being transpiled to es5, I believe this has to do with this issue: rollup/rollup-plugin-babel#260

I solve the problem for now by adding exclude: [/node_modules\/(?!(@tryghost)\/).*/], to my webpack config file.

baseConfig[0].module.rules.push({
  test: /\.jsx?$/,
  exclude: [/node_modules\/(?!(@tryghost)\/).*/],
  loaders: ['babel-loader'],
}

Please consider this on the next release. Let me know what you think and I will make a PR πŸ˜‰

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.