Laravel Mix does not compile import or require. Instead, it simply copies them.
It does not perform minification in production mode either, but that's a side-issue.
npm install some package.app.js:import package from 'package'; // Or package = require('package');
mix.babel('inputpath/app.js', 'outputpath/app.js'); to your webpack.mix.js.npm run dev or any other compilation script.The output file will just be the same as the input file. Meanwhile, other ES6 features _are_ compiled correctly (tested with classes and arrow syntax for example).
Am I missing something, or is this a bug?
Same thing happens to me. I found a workaround here. Don't know if it affects performance though.
mix.js('resources/assets/js/app.js', 'public/js');
mix.webpackConfig({
module: {
rules: [{
test: /\.js?$/,
use: [{
loader: 'babel-loader',
options: mix.config.babel()
}]
}]
}
});
@fiskhandlarn Thanks! That works for now. However, it seems like using mix.babel should just work.
For me, using mix.js without the config you mentioned works in development mode, but crashes in production mode (during minification). With the config, it also works in production.
@WouterFlorijn I agree, that would have been the best/easiest. :)
If the package you're requiring was written in es6, it won't be compiled down. You'd need to require the compiled version of that package.
@JeffreyWay The package I'm trying to require is my own written ES6 code for the app/site. It would be nice to be able to compile that with mix.babel. :)
Most helpful comment
Same thing happens to me. I found a workaround here. Don't know if it affects performance though.