-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Sorry in advance this is long-winded. I don’t know enough about frontend stuff to know what is important and what isn't, so I'm including everything that I think might be relevant.
I'm (hopefully) at the very end of a long process of migrating from the umaintained-for-over-two-years webpack-rails to webpacker, and everything is so close, but I have one dependency that is breaking in production but not in development. It appears to be due to magnification or mangling or something like that. It seems like a project called terser is what is being used now, but I'm not 100% sure.
maybe just exclude this from minification?
I'd be more than happy to exclude this file form minification, rather than figure out which options of mangle or compress or minify etc is the actual cause.
I see from terser's documentation https://webpack.js.org/plugins/terser-webpack-plugin#exclude to exclude a file you add
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
exclude: /\/excludes/,
}),
],
},
};
to webpack.config.js
. However, unlike webpack-rails, I don’t think webpacker uses webpack.config.js at all, and instead it's all in config/webpack/*
and config/webpack.yml
. That's okay, however I cant figure out how to get this configuration in there.
After doing the generate task to drop all the new files for webpacker, my producion.js is only
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
My environment.js is
const { environment } = require('@rails/webpacker')
const webpack = require('webpack');
environment.plugins.append("Provide", new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}));
module.exports = environment
I added some things in there to get jquery to work, but otherwise it's as it came from the generator.
I see that in this project's webpacker/package/environments/production.js
there is a lot of terser configuration, however I haven't tracked down yet how or if that gets called.
I'm using webpacker-4.0.7
gem and "@rails/webpacker": "^4.0.7"
, npm.
the actual problem
The project that is breaking for me is metrics-graphics and terser (or whatever is doing the minification) is doing this: