-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Automatically pick up .terserrc
#389
Comments
We avoid it because it is not official and reduce perf, better load once options and don't touch |
Isn't this a webpack repo? Adding it here would make it official for webpack users like webpack made Direct Terser support (which is probably what you mean by "official") could be suggested there, but probably only for its CLI tool anyway, not the API used by this plugin.
In the context of webpack I don't think a single 1KB read affects the performance in any significant way whatsoever. |
Yes, I mean
|
Maybe I should clarify that the intent of this issue is not necessarily to have external configuration, which isn't really useful since webpack already has its own configuration file, but to be able to customize Terser’s options without having to
|
I understand this, just want agree format of configuration and supported extensions. |
Hello! Terser already has a config file loading function, --config-file, but only on the CLI. The configuration file has basically the same format as the first argument to minify(), with some differences pertaining to the fact that strings are used to represent regexes. I'm delighted with this .terserrc thing, informal standards are awesome! I'm happy to allow users to specify the path to it on the API like is possible with the CLI (it might be a thing already, I'm not sure). Then webpack can find this file and pass its path over. |
🙌
Again this defeats the purpose of having a file. If it's not picked up automatically this isn't useful. Currently optimization: {
// Keeps it somewhat readable for AMO reviewers
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: false,
output: {
beautify: true,
indent_level: 2
}
}
})
]
} Currently also possible optimization: {
// Keeps it somewhat readable for AMO reviewers
minimizer: [
new TerserPlugin({
terserOptions: require('./.terserrc')
})
]
} What you're suggesting optimization: {
// Keeps it somewhat readable for AMO reviewers
minimizer: [
new TerserPlugin({
terserOptionsPath: './.terserrc'
})
]
} What I really want |
Love your ideal example here 😃 I would like to have that too, but there are a few reasons I'd prefer that webpack and other tools do this (potentially by importing some @terser/something module from npm)
So I don't mean to push back here -- I think a standard rc file is a very good goal to strive towards. I just want to make sure it's done right. Something like this has big implications (I had quite a few problems with .babelrc before) and I dislike releasing major versions because that causes other problems too. |
As a side note, I see this as something that could help debugging Terser itself. Lots of people come up to Terser and open issues about how something is crashing, often not knowing enough details to help me help them. A configuration file opens up the possibility of a more detailed bug report (think a "bug report" mode where comments indicate source map position and you can tell why the crash is happening and isolate a reproducible snippet more easily) |
Can the plugin access webpack
I think that's thinking too far ahead. Given that there are other ways to achieve the same, this would be an enhancement rather than a requirement. At most I'd expect a
IMHO it is clear: the closer to the user, the high the priority:
This is what TypeScript does for example:
Also Babel has extensive documentation on the matter, showing this also: https://babeljs.io/docs/en/configuration
Rollup does the same: https://rollupjs.org/guide/en/#command-line-flags
I think that this could also be implemented in Terser, but it can do so independently, whether in the CLI only or also via API like Babel does. If in the end both projects implement, the upper-most project can drop it. If this doesn't belong here, maybe webpack-cli could this:
|
Ideally tools should solve this on own side, because configurations very different and can be changed between releases, so |
I think we should call it "terser.config.js". |
function createTerserPlugin() {
const terserconfig: {
// minify: typeof TerserPlugin.terserMinify;
parallel: boolean;
terserOptions: MinifyOptions;
} = {
// minify: TerserPlugin.terserMinify,
terserOptions: {
ecma: 5,
parse: {
ecma: 2015,
},
compress: {
// warnings: !1,
comparisons: !1,
inline: 2,
drop_console: true,
drop_debugger: true,
pure_funcs: ["console.log"],
},
mangle: {
safari10: !0,
},
output: {
ecma: 5,
comments: !1,
ascii_only: !0,
},
},
parallel: !0,
};
if (fs.existsSync(path.resolve(__dirname, "terser.config.js"))) {
const mergedconfig = merge.recursive(
true,
terserconfig,
require(path.resolve(__dirname, "terser.config.js"))
) as typeof terserconfig;
//@ts-ignore
return new TerserPlugin<MinifyOptions>(mergedconfig);
}
//@ts-ignore
return new TerserPlugin<MinifyOptions>(terserconfig);
} |
"babel.config.js" "tsconfig.json" "postcss.config.js" |
Feature Proposal
Configuration could be automatically picked up by looking for
.terserrc
in the same directory aswebpack.config.js
like Parcel does:https://github.com/parcel-bundler/parcel/blob/39ff8330d68c6c0e01d9e8471dd94ce1eb2e62ec/packages/optimizers/terser/src/TerserOptimizer.js#L23
Feature Use Case
Parcel v2 lets me customize the minification step of Tercer by using a configuration file. It'd be great if
webpack
did this natively as well so that I don't have to install, require, and callnew TerserPlugin()
in webpack.config.js.terserc
also seen on thestandard-things/esm
repo, which loads it manually.The text was updated successfully, but these errors were encountered: