-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to configure terser? #2131
Comments
I think it might be babel and not terser. Babel/core-js is the one that polyfills things like Can you tell me if putting: If that doesn't work, can you show me the context where you are importing |
@jakeNiemiec wow that fixed it. Thank you!! I put it in I'm importing metrics-graphcis on a particular page, and the The pictures were the chrome debugger on that line that failed, I assume after all the source mapping, since the error messages didn't match up with the lines in the chrome debugger ( |
No, the problem is that you are re-transpiling code that has already been transpiled. I would future-proof things by putting it in Think about if you use Google Translate to pass a phrase through many different languages. In the same way, nuance is lost and the result you get can break depending on what you started with. From what I can tell, the Is everything working now, can this be closed? |
Ah okay, I see what you're saying. I wasn't aware that node_modules would already be transpiled at all. I thought you meant Thank you for your help! |
I'm still curious how to configure Terser. I previously configured UglifyJS to strip console statements like so: const uglifyOptions = environment.plugins.get('UglifyJs').options.uglifyOptions;
uglifyOptions.compress.drop_console = true; // Remove console statements but it seems the configuration completely changed in Webpacker 4 and so Terser (and before it, Uglify) is no longer available via related: #1235 (comment) |
You could try playing around with Here is where this is set ( webpacker/package/environments/production.js Lines 42 to 60 in 9e671a3
|
@jakeNiemiec thanks for getting me on the right path! This worked: environment.config.optimization.minimizer.find(m => m.constructor.name === 'TerserPlugin').options.terserOptions.compress.drop_console = true |
@jakeNiemiec I've run into what is more or less the same problem trying to use mapbox gl js with a relatively vanilla rails 6 webpacker setup (here's a related issue on the Mapbox repo). Your recommendation --
solved the problem, but it seems like a blunt instrument. I'm new to webpacker, but shouldn't default behavior transpile modules that need it and ignore ones that don't? Or, perhaps ignore all of them, like you're suggesting? EDIT I changed it to just exclude mapbox-gl here, but it still seems like an open question as to whether or not this is really the best solution? |
@ngottlieb @swrobel Glad to see you got it working.
The inclusion of the This results in a kind of fidelity loss where included global polyfills, like
I can't think of a scenario where not transpiling One helpful change that we could make would be to move the "Excluding node_modules From Being Transpiled By Babel-Loader" section from the upgrade doc to the readme doc since it is often required outside of upgrading from v3 to v4. @gauravtiwari @javan @dhh What do you think? I feel like I have seen this issue enough times over the past year to warrant some discussion on the pain points it causes. Webpack 5 is already on the horizon, Here are some earmarked examples from the past year since the
|
fixes rails/rails#35501 fixes rails#2131 fixes rails/rails#36278 fixes rails#2407 fixes rails#2114 fixes rails#1949 fixes rails#1865 fixes rails#1857
fixes rails/rails#35501 fixes #2131 fixes rails/rails#36278 fixes #2407 fixes #2114 fixes #1949 fixes #1865 fixes #1857
If someone needs, this is how I did: ` const environment = require('./environment') const TerserPlugin = require("terser-webpack-plugin"); module.exports = environment.toWebpackConfig() |
First, apologies for necro-ing an old (closed) issue. I think I'm either asking a silly question or revealing my ignorance here, but this doesn't make sense to me. The fidelity metaphor seems sensible, but if the transformation process is lossy, isn't that a bug in the transpiler/bundler/etc? To not transpile |
The expectation to only include non-transpiled modern features in the your source. That way, babel can include contingent code that gives old browsers the means to function despite the missing language feature.
@HarrisonB No, this is by design. The users who eventually get the script don't need a source file, they are sent a chopped-down version that turns If you have any other questions, feel free to email me. |
fixes rails/rails#35501 fixes rails/webpacker#2131 fixes rails/rails#36278 fixes rails/webpacker#2407 fixes rails/webpacker#2114 fixes rails/webpacker#1949 fixes rails/webpacker#1865 fixes rails/webpacker#1857
fixes rails/rails#35501 fixes rails/webpacker#2131 fixes rails/rails#36278 fixes rails/webpacker#2407 fixes rails/webpacker#2114 fixes rails/webpacker#1949 fixes rails/webpacker#1865 fixes rails/webpacker#1857
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
to
webpack.config.js
. However, unlike webpack-rails, I don’t think webpacker uses webpack.config.js at all, and instead it's all inconfig/webpack/*
andconfig/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
My environment.js is
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:
development
production
The text was updated successfully, but these errors were encountered: