Skip to content

Commit 9f7a866

Browse files
committed
Trying out the new webpack-manifest-plugin
1 parent f841ade commit 9f7a866

File tree

3 files changed

+39
-143
lines changed

3 files changed

+39
-143
lines changed
Lines changed: 1 addition & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1 @@
1-
/*
2-
* File is originally a direct copy from https://github.com/danethurber/webpack-manifest-plugin
3-
* at version 1.1.0.
4-
*
5-
* The library is licensed as MIT.
6-
*
7-
* There was then one change made in the code below for
8-
* this library.
9-
*/
10-
11-
var path = require('path');
12-
var fse = require('fs-extra');
13-
var _ = require('lodash');
14-
15-
function ManifestPlugin(opts) {
16-
this.opts = _.assign({
17-
basePath: '',
18-
publicPath: '',
19-
fileName: 'manifest.json',
20-
stripSrc: null,
21-
transformExtensions: /^(gz|map)$/i,
22-
writeToFileEmit: false,
23-
cache: null
24-
}, opts || {});
25-
}
26-
27-
ManifestPlugin.prototype.getFileType = function(str) {
28-
str = str.replace(/\?.*/, '');
29-
var split = str.split('.');
30-
var ext = split.pop();
31-
if (this.opts.transformExtensions.test(ext)) {
32-
ext = split.pop() + '.' + ext;
33-
}
34-
return ext;
35-
};
36-
37-
ManifestPlugin.prototype.apply = function(compiler) {
38-
var outputName = this.opts.fileName;
39-
var cache = this.opts.cache || {};
40-
var moduleAssets = {};
41-
42-
compiler.plugin("compilation", function (compilation) {
43-
compilation.plugin('module-asset', function (module, file) {
44-
moduleAssets[file] = path.join(
45-
path.dirname(file),
46-
path.basename(module.userRequest)
47-
);
48-
/* *** MODIFICATION START *** */
49-
// for Windows, we want the keys to use /, not \
50-
// (and path.join will obviously use \ in Windows)
51-
if (process.platform === 'win32') {
52-
moduleAssets[file] = moduleAssets[file].replace(/\\/g, '/');
53-
}
54-
/* *** MODIFICATION END *** */
55-
});
56-
});
57-
58-
compiler.plugin('emit', function(compilation, compileCallback) {
59-
var stats = compilation.getStats().toJson();
60-
var manifest = {};
61-
62-
_.merge(manifest, compilation.chunks.reduce(function(memo, chunk) {
63-
var chunkName = chunk.name ? chunk.name.replace(this.opts.stripSrc, '') : null;
64-
65-
// Map original chunk name to output files.
66-
// For nameless chunks, just map the files directly.
67-
return chunk.files.reduce(function(memo, file) {
68-
// Don't add hot updates to manifest
69-
if (file.indexOf('hot-update') >= 0) {
70-
return memo;
71-
}
72-
if (chunkName) {
73-
memo[chunkName + '.' + this.getFileType(file)] = file;
74-
} else {
75-
memo[file] = file;
76-
}
77-
return memo;
78-
}.bind(this), memo);
79-
}.bind(this), {}));
80-
81-
// module assets don't show up in assetsByChunkName.
82-
// we're getting them this way;
83-
_.merge(manifest, stats.assets.reduce(function(memo, asset) {
84-
var name = moduleAssets[asset.name];
85-
if (name) {
86-
memo[name] = asset.name;
87-
}
88-
return memo;
89-
}, {}));
90-
91-
/* *** MODIFICATION START *** */
92-
if (this.opts.basePath && this.opts.publicPath) {
93-
// A modification made to the plugin for Encore
94-
manifest = _.reduce(manifest, function(memo, value, key) {
95-
memo[this.opts.basePath + key] = this.opts.publicPath + value;
96-
return memo;
97-
}.bind(this), {});
98-
/* *** MODIFICATION END *** */
99-
} else if (this.opts.basePath) {
100-
// Append optional basepath onto all references.
101-
// This allows output path to be reflected in the manifest.
102-
manifest = _.reduce(manifest, function(memo, value, key) {
103-
memo[this.opts.basePath + key] = this.opts.basePath + value;
104-
return memo;
105-
}.bind(this), {});
106-
} else if (this.opts.publicPath) {
107-
// Similar to basePath but only affects the value (similar to how
108-
// output.publicPath turns require('foo/bar') into '/public/foo/bar', see
109-
// https://github.com/webpack/docs/wiki/configuration#outputpublicpath
110-
manifest = _.reduce(manifest, function(memo, value, key) {
111-
memo[key] = this.opts.publicPath + value;
112-
return memo;
113-
}.bind(this), {});
114-
}
115-
116-
Object.keys(manifest).sort().forEach(function(key) {
117-
cache[key] = manifest[key];
118-
});
119-
120-
var json = JSON.stringify(cache, null, 2);
121-
122-
compilation.assets[outputName] = {
123-
source: function() {
124-
return json;
125-
},
126-
size: function() {
127-
return json.length;
128-
}
129-
};
130-
131-
if (this.opts.writeToFileEmit) {
132-
var outputFolder = compilation.options.output.path;
133-
var outputFile = path.join(outputFolder, this.opts.fileName);
134-
135-
fse.outputFileSync(outputFile, json);
136-
}
137-
138-
compileCallback();
139-
}.bind(this));
140-
};
141-
142-
module.exports = ManifestPlugin;
1+
module.exports = require('webpack-manifest-plugin');

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"webpack": ">=2.2.0 <4",
4747
"webpack-chunk-hash": "^0.5.0",
4848
"webpack-dev-server": "^2.4.5",
49+
"webpack-manifest-plugin": "v2.0.0-rc.1",
4950
"yargs": "^8.0.1"
5051
},
5152
"devDependencies": {

yarn.lock

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,16 @@ friendly-errors-webpack-plugin@^1.6.1:
27102710
error-stack-parser "^2.0.0"
27112711
string-width "^2.0.0"
27122712

2713+
fs-extra@^0.30.0:
2714+
version "0.30.0"
2715+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.30.0.tgz#f233ffcc08d4da7d432daa449776989db1df93f0"
2716+
dependencies:
2717+
graceful-fs "^4.1.2"
2718+
jsonfile "^2.1.0"
2719+
klaw "^1.0.0"
2720+
path-is-absolute "^1.0.0"
2721+
rimraf "^2.2.8"
2722+
27132723
fs-extra@^2.0.0:
27142724
version "2.1.2"
27152725
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
@@ -2900,7 +2910,7 @@ globule@^1.0.0:
29002910
lodash "~4.17.4"
29012911
minimatch "~3.0.2"
29022912

2903-
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
2913+
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
29042914
version "4.1.11"
29052915
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
29062916

@@ -3756,6 +3766,16 @@ kind-of@^6.0.0, kind-of@^6.0.2:
37563766
version "6.0.2"
37573767
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"
37583768

3769+
klaw@^1.0.0:
3770+
version "1.3.1"
3771+
resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439"
3772+
optionalDependencies:
3773+
graceful-fs "^4.1.9"
3774+
3775+
lazy-cache@^0.2.3:
3776+
version "0.2.7"
3777+
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-0.2.7.tgz#7feddf2dcb6edb77d11ef1d117ab5ffdf0ab1b65"
3778+
37593779
lazy-cache@^1.0.3:
37603780
version "1.0.4"
37613781
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
@@ -4259,6 +4279,14 @@ nanomatch@^1.2.9:
42594279
snapdragon "^0.8.1"
42604280
to-regex "^3.0.1"
42614281

4282+
4283+
version "1.0.1"
4284+
resolved "https://registry.yarnpkg.com/mutexify/-/mutexify-1.0.1.tgz#9880206795d89e75efc1bcb4b4f52ebbd796e5e7"
4285+
4286+
nan@^2.3.0, nan@^2.3.2:
4287+
version "2.6.2"
4288+
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"
4289+
42624290
native-promise-only@^0.8.1:
42634291
version "0.8.1"
42644292
resolved "https://registry.yarnpkg.com/native-promise-only/-/native-promise-only-0.8.1.tgz#20a318c30cb45f71fe7adfbf7b21c99c1472ef11"
@@ -6772,6 +6800,14 @@ webpack-dev-server@^2.4.5:
67726800
webpack-dev-middleware "1.12.2"
67736801
yargs "6.6.0"
67746802

6803+
6804+
version "2.0.0-rc.1"
6805+
resolved "https://registry.yarnpkg.com/webpack-manifest-plugin/-/webpack-manifest-plugin-2.0.0-rc.1.tgz#82b03afd05a308a36a6066f1c37ac9ff1c9d5e8a"
6806+
dependencies:
6807+
fs-extra "^0.30.0"
6808+
lodash ">=3.5 <5"
6809+
mutexify "1.0.1"
6810+
67756811
webpack-notifier@^1.5.0:
67766812
version "1.6.0"
67776813
resolved "https://registry.yarnpkg.com/webpack-notifier/-/webpack-notifier-1.6.0.tgz#ffac8e55ff8c469752b8c1bbb011a16f10986e02"

0 commit comments

Comments
 (0)