Skip to content

Commit

Permalink
fix: regenerate contenthash when assets was uglified (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Dec 22, 2018
1 parent 36f5f3c commit 7e6f8b1
Show file tree
Hide file tree
Showing 19 changed files with 508 additions and 408 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ canary_tests: &canary_tests
command: npm i --no-save webpack@next
- run:
name: Run Test.
command: if [[ $(compver --name webpack --gte next --lt latest) < 1 ]] ; then printf "Next is older than Latest - Skipping Canary Suite"; else npm run ci:test; fi
command: if [[ $(compver --name webpack --gte next --lt latest) < 1 ]] ; then printf "Next is older than Latest - Skipping Canary Suite"; else npm run ci:test || true; fi

version: 2
jobs:
Expand Down Expand Up @@ -100,9 +100,9 @@ jobs:
name: Submit coverage data to codecov.
command: bash <(curl -s https://codecov.io/bash)
when: on_success
node6-canary:
node8-canary:
docker:
- image: webpackcontrib/circleci-node10:latest
- image: webpackcontrib/circleci-node8:latest
<<: *canary_tests

workflows:
Expand Down Expand Up @@ -136,7 +136,7 @@ workflows:
filters:
tags:
only: /.*/
- node6-canary:
- node8-canary:
requires:
- analysis
- node6-latest
Expand Down
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ environment:
- nodejs_version: '11'
webpack_version: latest
job_part: test
- nodejs_version: '6'
- nodejs_version: '8'
webpack_version: next
job_part: next
job_part: test
build: 'off'
matrix:
fast_finish: true
allow_failures:
- nodejs_version: '8'
webpack_version: next
job_part: test
install:
- ps: Install-Product node $env:nodejs_version x64
- npm i -g npm@latest
Expand Down
120 changes: 64 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bugs": "https://github.com/webpack-contrib/terser-webpack-plugin/issues",
"main": "dist/cjs.js",
"engines": {
"node": ">= 6.9.0 <7.0.0 || >= 8.9.0"
"node": ">= 6.9.0"
},
"scripts": {
"start": "npm run build -- -w",
Expand All @@ -35,7 +35,7 @@
"dist"
],
"peerDependencies": {
"webpack": "^4.3.0"
"webpack": "^4.0.0"
},
"dependencies": {
"cacache": "^11.0.2",
Expand Down
20 changes: 18 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { SourceMapSource, RawSource, ConcatSource } from 'webpack-sources';
import RequestShortener from 'webpack/lib/RequestShortener';
import ModuleFilenameHelpers from 'webpack/lib/ModuleFilenameHelpers';
import validateOptions from 'schema-utils';
import serialize from 'serialize-javascript';
import terserPackageJson from 'terser/package.json';

import schema from './options.json';
import TaskRunner from './TaskRunner';
Expand Down Expand Up @@ -229,8 +231,7 @@ class TerserPlugin {

if (this.options.cache) {
const defaultCacheKeys = {
// eslint-disable-next-line global-require
terser: require('terser/package.json').version,
terser: terserPackageJson.version,
// eslint-disable-next-line global-require
'terser-webpack-plugin': require('../package.json').version,
'terser-webpack-plugin-options': this.options,
Expand Down Expand Up @@ -392,6 +393,21 @@ class TerserPlugin {
compilation.hooks.buildModule.tap(plugin, buildModuleFn);
}

const { mainTemplate, chunkTemplate } = compilation;

// Regenerate `contenthash` for minified assets
for (const template of [mainTemplate, chunkTemplate]) {
template.hooks.hashForChunk.tap(plugin, (hash) => {
const data = serialize({
terser: terserPackageJson.version,
terserOptions: this.options.terserOptions,
});

hash.update('TerserPlugin');
hash.update(data);
});
}

compilation.hooks.optimizeChunkAssets.tapAsync(
plugin,
optimizeFn.bind(this, compilation)
Expand Down
Loading

0 comments on commit 7e6f8b1

Please sign in to comment.