So, I tried to get Sweet.js to work on my ES6 project, using Webpack to compile it. I could make everyone work separately, but no matter how I tried to collect them, he gave some error ... I think this is mainly due to the source maps, since the error usually looks like something like:
Module build failed: Error: C:/Users/.../index.js: Invalid mapping: {"generated":{"line":4,"column":12, "lastColumn":null},"source":null,"original":{"line":null,"column":null},"name":null}
And here is the code that does not work:
webpack.config.js:
module.exports = { entry: './public_html/script/src/index.js', // ... module: { loaders: [ { test: /\.js$/, exclude: /node_modules.*\.js/, loader: 'babel!sweetjs?modules[]=./macros.sjs&sourceMap=true' }, // ... ] }, // ... devtool: 'source-map', // ... };
macros.sjs:
macro (=~) { rule infix { $x | $y } => { !!$y.test($x) } }; export (=~); macro (!=~) { rule infix { $x | $y } => { !$y.test($x) } }; export (!=~);
index.js:
let x = "asdf", p = /a/i; x =~ p;
Loader reversal did not work, since Babel did not know what to do with macros. By removing the Babel bootloader, he compiled it, but then (with more complicated things) Webpack failed because he did not know what to do with ES6 things.
So far, I have not found anything about using both the babel and sweetjs downloaders at once ... Is this possible?
Edit: So, I found a bug with the sweetjs bootloader: https://github.com/jlongster/sweetjs-loader/issues/4
Setting true to false fixes the problem and creates another. Sweet.js seems to put some garbage data at the bottom of the files, which contradicts the loading of the Babel and Webpack module. This error occurs several times for assembly:
ERROR in ./public_html/script/src/main-menu/index.js Module build failed: Error: Line 56: Unexpected token ILLEGAL [... } ) ; ...]