Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

feat: support minify function option #325

Merged
merged 1 commit into from Jul 12, 2018

Conversation

alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented Jul 3, 2018

One question: what do with extracting comment for custom minify function, if people use uglify-js/terser our logic https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/master/src/uglify/minify.js#L45 is work good, maybe we should export this function to avoid copy/paste this code

@alexander-akait alexander-akait force-pushed the feat-minify-function-option branch 3 times, most recently from a0656df to d1152b2 Compare July 3, 2018 15:54
@alexander-akait alexander-akait force-pushed the feat-minify-function-option branch 2 times, most recently from 0802668 to f8a79a1 Compare July 3, 2018 16:10
README.md Outdated
@@ -89,6 +90,8 @@ module.exports = {

### `cache`

If you use custom `minify` function please read `minify` option section for cache invalidation correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a custom, see syntax below

README.md Outdated
@@ -178,6 +181,8 @@ Number of concurrent runs.

### `sourceMap`

If you use custom `minify` function please read `minify` option section for handle source maps correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use custom minifyfunction please readminify option section for handle source maps correctly. -> If you use your own minifyfunction please read theminify section for handling source maps correctly.

README.md Outdated
// );
// },
minify(file, sourceMap) {
// Look https://github.com/mishoo/UglifyJS2#minify-options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Look, a link is enough perhaps

README.md Outdated
// );
// },
minify(file, sourceMap) {
// Look https://github.com/fabiosantoscode/terser#minify-options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strip Look

const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);

expect(errors).toMatchSnapshot('errors');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is needed, jest will resolve it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ev1stensberg will be done in other PR (refactor tests) 👍

function removeAbsoluteSourceMapSources(source) {
if (source.map && source.map.sources) {
// eslint-disable-next-line no-param-reassign
source.map.sources = source.map.sources.map(sourceFromMap => path.relative(process.cwd(), sourceFromMap));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way to copy and reassign instead of directly mutating here? Perhaps extracting into a variable and reassigning would be better https://stackoverflow.com/questions/34716651/js-array-prototype-map-happens-to-be-mutable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ev1stensberg why? It is increase lines of code and decrease perf, but we just need remove absolute path. I don't think it is critical here.


for (const file in stats.compilation.assets) {
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
expect(removeAbsoluteSourceMapSources(stats.compilation.assets[file].sourceAndMap())).toMatchSnapshot(file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertion is a bit long, maybe a variable to hold the assertion value would be good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ev1stensberg big in snapshots? I think it is normal, it is allow to catch some strange problem with source map and uglification

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Thought it would be better to test variables containing the values, but that might be hard with compilation instances

Copy link
Contributor

@ooflorent ooflorent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes work but I don't like the minify option. I think this option is a too low-level. Having a plugin per minifier would have been better.

In a near future (🤞) when we will have specified plugins, this option would no longer be relevant. Hence my hesitation about merging this.

README.md Outdated
]
```

By default plugin use `uglify-es` package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ooflorent same people want to use own minification (forks) and without this low level function it is impossible, creating new plugin for this situation is not good solution, because it is require copy/paste 99% code of plugin, also we other fix small problems, this will require people to constantly monitor this and cause a lot of inconvenience. Also it is simple way to test alpha/beta/rc/etc versions.

@alexander-akait alexander-akait force-pushed the feat-minify-function-option branch 2 times, most recently from d929a6a to 9024f0a Compare July 9, 2018 14:00
@alexander-akait
Copy link
Member Author

/cc @ooflorent please review, it is one blocker for terser and future minimize plugins

@alexander-akait alexander-akait merged commit 0174605 into master Jul 12, 2018
@alexander-akait alexander-akait deleted the feat-minify-function-option branch July 12, 2018 11:04
@kzc
Copy link

kzc commented Jul 12, 2018

Something to consider... if the default minify function is changed, the version remains "uglify-es":"3.3.9" in the uglifyjs-webpack-plugin cache key:

if (this.options.cache) {
const defaultCacheKeys = {
'uglify-es': versions.uglify,

and the cached assets will be invalid.

@alexander-akait
Copy link
Member Author

@kzc it is not critical, uglify-es is not updated long time, cache will works as expected

@kzc
Copy link

kzc commented Jul 12, 2018

uglify-es is not updated long time, cache will works as expected

Until the module with the minify replacement function is upgraded - terser, uglify-js, or whatever. You might mention in the docs if this minify field is overriden or dependencies are updated then the user should delete their build cache. You could also elect to allow the user to provide a custom version string to workaround this issue.

@alexander-akait
Copy link
Member Author

@kzc PR welcome

@alexander-akait
Copy link
Member Author

Also we provide way to invalidate cache https://github.com/webpack-contrib/uglifyjs-webpack-plugin#terser

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants