Closed roarkmccolgan closed 3 years ago
@roarkmccolgan I think since I wrote that code example, the way that Laravel Mix has changed - probably due to a change in Webpack.
If you add .dump()
to the end of your chain, the Webpack config will be outputted to the console. You will see that all the snippet does now is to append to the module.rules
array.
I think what you want to do is to change the excluded folders of a particular rule. The rule for JavaScript is generated here.
.override()
seems to be the solution.
mix.override(webpackConfig => {
let javascriptIndex = null;
webpackConfig.module.rules.forEach(function (value, index) {
if (value['test'].toString() === '/\\.(cjs|mjs|jsx?|tsx?)$/') {
javascriptIndex = index;
}
});
if (javascriptIndex) {
delete webpackConfig.module.rules[javascriptIndex]['exclude'];
}
})
That said, this won't just cause Laravel Mix and this plugin to polyfill the missing features, but to recompile the package from source. This could cause issues.
Give it a try and let me know.
@scottcharlesworth this approach worked great for my needs, thanks! Instead of including everything I just wanted to include a single package from node_modules, and potentially more later, so I have an array of transpiledNodeModules
and then reassign exclude to the following:
new RegExp('(node_modules\\/(?!(' + transpiledNodeModules.join('|') + ')\\/).*|bower_components)')
I'm somewhat surprised that there is not an easier way to do this out of the box with Mix.
I cannot get this package to compile the dependencies, I've seen a few posts on getting this to compile dependencies and the solutions seemed to be adding this to webpack.mix.js
Originally posted by @scottcharlesworth in https://github.com/scottcharlesworth/laravel-mix-polyfill/issues/24#issuecomment-627839745
I have tried this and my node modules are still not being compiled.
I also tried changing
exclude: /(bower_components)/,
toexclude: /(node_modules)/,
but it also didn't workI'm using: Laravel Mix 6.0.6 webpack 5.21.2
My complete mix file is below:
The offending code is:
Object.assign
in one of the packagesPlease can you try help me?
Thanks