GithubHelp home page GithubHelp logo

Comments (14)

lourd avatar lourd commented on May 30, 2024 1

Hey @emcniece, thanks for your initial work. One simple fix is to use explicit userland modules instead of relying on polyfills. For example, use object-assign and the object-keys npm packages instead of relying on Object.keys and Object.assign being implemented in the runtime.

I believe those are the only functions that babel-polyfill is actually fulfilling in this package.

from particle-api-js.

monkbroc avatar monkbroc commented on May 30, 2024 1

Version 6.0.1 now uses babel-runtime instead of babel-polyfill. If anybody is still having an issue with the transpiler or sees only one instance of babel-polyfill is allowed please comment and I'll reopen this issue.

from particle-api-js.

emcniece avatar emcniece commented on May 30, 2024 1

Confirmed that this works within my project - thank you!

from particle-api-js.

brycekahle avatar brycekahle commented on May 30, 2024

For instance, polyfilling Promises when Node 4 and 5 have them natively.

A polyfill will not override an existing native implementation. The difference between babel-polyfill and babel-runtime is whether or not the global namespace is modified to support ES2015.

I can see why an app developer wouldn't want extra code that they don't use. I don't like that we get a full polyfill while only using a few of them. I want to try a couple different ways to get only specific ones we use. Would that alleviate your concerns?

from particle-api-js.

lourd avatar lourd commented on May 30, 2024

Sure. I've seen from a few libraries that want to be explicit specifying individual babel plugins in the .babelrc file instead of using a preset.

from particle-api-js.

brycekahle avatar brycekahle commented on May 30, 2024

That works for syntax transforms but not runtime dependencies.

from particle-api-js.

lourd avatar lourd commented on May 30, 2024

Right. The solutions I can think of are either tree-shaking in the build process with Rollup or Webpack 2, or switch to explicitly using each polyfill you need.

from particle-api-js.

emcniece avatar emcniece commented on May 30, 2024

So I just hit an issue while trying to use particle-api-js in a pre-compiled angular environment:

Uncaught Error: only one instance of babel-polyfill is allowed

I'm including the script directly in HTML because this is a restrictive node/angular plugin-esque system and I can't get NPM modules through to the front end, which is frustrating to say the least. Is this related to this issue?

from particle-api-js.

emcniece avatar emcniece commented on May 30, 2024

@lourd @brycekahle a penny for your thoughts :D

from particle-api-js.

lourd avatar lourd commented on May 30, 2024

Haha 😉

@brycekahle, any progress made on this? It looks like the methods that may need polyfills are limited to Object.assign and Object.keys.

from particle-api-js.

brycekahle avatar brycekahle commented on May 30, 2024

Unfortunately no progress. I'm pretty swamped at the moment so if you have time to put together a PR that polyfills only the necessary features that would be really helpful.

from particle-api-js.

emcniece avatar emcniece commented on May 30, 2024

Cool, thanks @brycekahle!

@lourd - this is a bit beyond my knowledge, but I'll try to help out. Here's a first step - it's not working, tests fail on trying to find babel-runtime. I'll navigate this maze over the next week or two, but some tips would be greatly appreciated ;)

https://github.com/emcniece/particle-api-js/tree/babel-runtime-conversion
https://github.com/spark/particle-api-js/compare/master...emcniece:babel-runtime-conversion?expand=1

from particle-api-js.

emcniece avatar emcniece commented on May 30, 2024

I gave your links a shot tonight, and they don't seem to be compatible as they use require instead of import. I looked around for some other ES6 ObjectAssign polyfills and they all seem to use require, which Babel fails on. (6:1 error 'require' is not defined no-undef)

I must be missing something obvious...

from particle-api-js.

lourd avatar lourd commented on May 30, 2024

That sounds like a linter error, not an actual program error.

require is built into Node. It's part of what's known as the CommonJS module system. import is part of the ES6 module system, as you mentioned. The Babel configuration for this project transpiles the import statements into require statements. Node does not support ES6 modules natively yet (work is underway, Google '.ejs vs package.json' for some fun reading over the debates happening right now).

So you can use import without a problem, i.e. import assign from 'object-assign'. The linter is setup to enforce using the new syntax.

from particle-api-js.

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.