-
Notifications
You must be signed in to change notification settings - Fork 127
Use Babel for builds #31
Comments
Hey, @AndrewRedican should you have some time can you review the updates to the build system? It is pretty much a complete redo, so I'll try to explain the changes as much as possible. See the babel-builds branch. First of all is the move from webpack to babel for building the library.Why? While webpack is an awesome tool, it is in my experience not the greatest tool for compiling libraries: The library still compiles to a single bundle.js, which is not desired for them(Always includes all code even if they don't need all of it, they can't properly apply their own transformers/source maps/etc to it, ...) With the babel backed compilation we retain the same folder/file structure, allowing users to manually import parts of the library, while still transpiling the module to plain commonjs es2015. We currently achieve this by using the WebpackCopyPlugin, but this solution doesn't allow us to transform the code and is clearly not scalable as the project will evolve. package.json scriptsThere are a decent amount of new package.json scripts. Let's go though them:
Problems?I still have to wrap my head around jest and unit testing in general, so it's very likely that the tests fail at the moment. - I got it to work to a point where it starts and doesn't fail due to syntax errors, but fails due to an error about localStorage in jsdom. I'll look into that tomorrow. This is a breaking change for users. The previous import paths were e.g. |
@PatrickSachs, 🔥 This is great! I think this is the correct approach for bundling the project. I too noticed it was very difficult to create multiple bundles in Webpack (I tried setting up configuration for multiple bundles when I realized the
I too think
Can you expand on this? I didn't quite follow. I think this update clears the biggest concerns of the Streamline milestone. Please give me few hours to get familiar with this new configuration, I'll check tests. |
Certainly - Browser support for ES6+ is getting better and better. Some browsers like the Safari 10, Chrome 61, ... actually already have native support for the ES6 module ecosystem( The This code can then be consumed either by modern runtimes(like the mentioned Safari, or node.js with the right flags), or used by the build system of other projects to transpile & polyfill the code the way they want to. Since this build system is heavily based on the way material-ui has set theirs up, see this PR in material-ui for some discussion about the merits of having an ES6 output: mui/material-ui#8772 If it seems like too much overhead for now(which I can understand, I was initially rather skeptic myself) we could remove the es configuration and just compile to a single es5 output. The benefit of this would be simplicity and reduced build time. |
I thought about this system today, and I think having a simpler build system is better and less confusing. We still have two different build outputs, but apply the same babel transformers to all of them. The only difference is that one output's module system is commonjs (export, require - something that node.js can use), and the other is es (export, import - something browsers can use). Most bundlers should understand both module systems.
One downside of this is that we transpile both setups to ES versions compatible with the browsers specified in the Let me know if you agree with this change or want to go back to the old configuration. |
Hey @PatrickSachs, Sorry I haven't been able to get back to you. I haven't had the time to finish reviewing. I'll confirm today. That being said, I am happy to provide two different versions for distribution:
I don't mind the "complicated" setup. I don't mind longer build times either. As long as we are providing the flexible solutions for other developers that would like to use the project, I think it is a fair trade. Do you think the new set up proposed is scalable? For example, would we have trouble adding more files in the |
No worries! Take your time, it's important to set up a good and scalable compiler.
As of now all versions are compiled to IE11 compatible code. This has to be battle tested, but that's what the configuration tells Babel to do. targets: {
ie: 11,
edge: 14,
firefox: 45,
chrome: 49,
safari: 10,
node: '6.11',
} We might need a plugin explicitly for polyfills in the future. (To avoid problems like #26)
So, have the commonjs Version be the one compiled down to "IE Level"-Code, and the ES one be modern JavaScript? (Essentially somewhat like before)
No, the setup will transpile the folder structure 1:1, so any directory or file added in /src will be included in the transpiled /dist output. |
Alright, I'm rather statisfied with this change: As discussed, the commonjs version will be transpiled & polyfilled to something that should be compatible with older browsers, while the ES version stays largely untouched(aside from transpiling react and language proposals) allowing the user to decide how to further compile the code. I'll go ahead and create a PR for this change. Let me know if run into any issues during your test or have additional suggestions/requests for changes. |
I'll be adding new base tests. I'll also look into browser compatability testing. I'll be using this |
This task is complete |
Webpack is meant for the final bundling of a code base. Libraries are better built using raw Babel. This allows the user to use their own module bundler/polyfills/etc...
This entails upgrading to the latest Babel version and removing webpack as a dev-dependency for the library (we will still use it for the example).
The text was updated successfully, but these errors were encountered: