Skip to content

Commit 8dec303

Browse files
authored
Merge pull request #8 from bestknighter/master
2 parents 0e44776 + c332fd8 commit 8dec303

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Use [npm version](https://docs.npmjs.com/cli/version) to bump your package versi
1818
yarn add --dev webpack-manifest-version-sync-plugin
1919
```
2020

21+
or
22+
23+
```sh
24+
npm install webpack-manifest-version-sync-plugin --save-dev
25+
```
26+
2127
## Usage
2228

2329
```js

index.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,28 @@ class ManifestVersionSyncPlugin {
1111
}
1212

1313
apply(compiler) {
14-
compiler.hooks.emit.tapAsync('ManifestVersionSyncPlugin', (compilation, callback) => {
15-
// Skip watch mode
16-
if (compilation.options.watch) {
17-
return callback();
18-
}
14+
compiler.hooks.compilation.tap('ManifestVersionSyncPlugin', (compilation, compilationParams) => {
15+
compilation.hooks.afterProcessAssets.tap('ManifestVersionSyncPlugin', () => {
16+
const { packagePath, manifestPath } = this.options;
1917

20-
const { packagePath, manifestPath } = this.options;
21-
const { version } = JSON.parse(fs.readFileSync(packagePath).toString());
22-
const manifest = JSON.parse(compilation.assets[manifestPath].source().toString());
23-
const content = JSON.stringify({ ...manifest, version }, undefined, 2);
24-
25-
compilation.assets[manifestPath] = {
26-
source: function() {
27-
return content;
28-
},
29-
size: function() {
30-
return Buffer.byteLength(content);
31-
},
32-
};
33-
34-
callback();
18+
// Skip watch mode
19+
if (compilation.options.watch || compilation.assets[manifestPath] == undefined) {
20+
return;
21+
}
22+
23+
const { version } = JSON.parse(fs.readFileSync(packagePath).toString());
24+
const manifest = JSON.parse(compilation.assets[manifestPath].source().toString());
25+
const content = JSON.stringify({ ...manifest, version }, undefined, 2);
26+
27+
compilation.assets[manifestPath] = {
28+
source: function() {
29+
return content;
30+
},
31+
size: function() {
32+
return Buffer.byteLength(content);
33+
},
34+
};
35+
});
3536
});
3637
}
3738
}

0 commit comments

Comments
 (0)