stealjs / steal-tools

Build easy. Load fast.
https://stealjs.com/docs/steal-tools.html
MIT License
67 stars 23 forks source link

treeshaking force compiling to ES5 #1156

Open pYr0x opened 4 years ago

pYr0x commented 4 years ago

Hey, i had an issue with await and compiling to ES6. i used the new forceES5: false option to avoid compiling to ES5. it worked on stealjs (in the browser). But if i want to create a bundle, steal-tools will compile all my code to ES5, if treeshaking is on. Here is my Slack issue: https://bitovi-community.slack.com/archives/CFDDX9MJS/p1582789198006000

And here is my demo: https://github.com/pYr0x/steal-es6 use npm run build to create a bundle. In the generated index.js i will find code like

var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {

which mean that that await is compiled to a es5 generator function

frank-dspeed commented 4 years ago

when you are working with es6 @pYr0x i can supply you a working rollup config with remove-steal and steal-resolve support at last for canjs it does not support the additional hackish steal imports like ~ or module/module while i am not really sure about the latest

but at last you could do a real es6+ build of canjs also using lebab to fix and clean the canjs source so that it is really working without double assignments to var names and all this object patching avoided.

it is not perfect as I still will need to do a complete independent fork of canjs to fix all the design issues. but it produces the best working es6 build of canjs that is possible today with that legacy code.

conclusion

if your modules are using real valid ECMAScript syntax for imports you can use rollup + myconfig to create awsome ESNext canjs bundels.

pYr0x commented 4 years ago

hey @frank-dspeed, it would be nice if you can share your rollup config in a github gist.