Skip to content

Commit 1930109

Browse files
committed
minor #164 Trying out the new webpack-manifest-plugin (weaverryan)
This PR was squashed before being merged into the master branch (closes #164). Discussion ---------- Trying out the new webpack-manifest-plugin This is not ready to be merged yet... as we should wait for a stable release. But, let's see if the tests pass :). We originally "forked" this library internally due to 2 issues, both of which should have been fixed in version 2 of the library. Should fix #140. TODOS: - Remove the old `webpack-manifest-plugin.js` file entirely and update paths to require the actual library instead of this - Stop passing the `publicPath` option to the plugin, as this is not supported anymore (I believe it's just being ignored right now) Commits ------- 6657a78 using the module directly and removing publicPath option, which is gone 9f7a866 Trying out the new webpack-manifest-plugin
2 parents f841ade + 6657a78 commit 1930109

File tree

7 files changed

+47
-155
lines changed

7 files changed

+47
-155
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/plugins/manifest.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const ManifestPlugin = require('../webpack/webpack-manifest-plugin');
12+
const ManifestPlugin = require('webpack-manifest-plugin');
1313
const PluginPriorities = require('./plugin-priorities');
1414
const applyOptionsCallback = require('../utils/apply-options-callback');
1515

@@ -28,8 +28,6 @@ module.exports = function(plugins, webpackConfig) {
2828

2929
const manifestPluginOptions = {
3030
basePath: manifestPrefix,
31-
// guarantee the value uses the public path (or CDN public path)
32-
publicPath: webpackConfig.getRealPublicPath(),
3331
// always write a manifest.json file, even with webpack-dev-server
3432
writeToFileEmit: true,
3533
};
Lines changed: 8 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,15 @@
11
/*
2-
* File is originally a direct copy from https://github.com/danethurber/webpack-manifest-plugin
3-
* at version 1.1.0.
2+
* This file is part of the Symfony Webpack Encore package.
43
*
5-
* The library is licensed as MIT.
4+
* (c) Fabien Potencier <fabien@symfony.com>
65
*
7-
* There was then one change made in the code below for
8-
* this library.
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
98
*/
109

11-
var path = require('path');
12-
var fse = require('fs-extra');
13-
var _ = require('lodash');
10+
'use strict';
1411

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-
}
12+
const logger = require('../logger');
13+
logger.deprecation('The lib/webpack/webpack-manifest-plugin.js module is deprecated: require the library directly now: require(\'webpack-manifest-plugin\').');
2614

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;
15+
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": {

test/config-generator.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const WebpackConfig = require('../lib/WebpackConfig');
1414
const RuntimeConfig = require('../lib/config/RuntimeConfig');
1515
const configGenerator = require('../lib/config-generator');
1616
const ExtractTextPlugin = require('extract-text-webpack-plugin');
17-
const ManifestPlugin = require('./../lib/webpack/webpack-manifest-plugin');
17+
const ManifestPlugin = require('webpack-manifest-plugin');
1818
const CleanWebpackPlugin = require('clean-webpack-plugin');
1919
const webpack = require('webpack');
2020

@@ -153,7 +153,6 @@ describe('The config-generator function', () => {
153153

154154
expect(actualConfig.output.publicPath).to.equal('/build/');
155155
const manifestPlugin = findPlugin(ManifestPlugin, actualConfig.plugins);
156-
expect(manifestPlugin.opts.publicPath).to.equal('/build/');
157156
// basePath matches publicPath, *without* the opening slash
158157
// we do that by convention: keys do not start with /
159158
expect(manifestPlugin.opts.basePath).to.equal('build/');
@@ -171,7 +170,6 @@ describe('The config-generator function', () => {
171170

172171
expect(actualConfig.output.publicPath).to.equal('/subdirectory/build/');
173172
const manifestPlugin = findPlugin(ManifestPlugin, actualConfig.plugins);
174-
expect(manifestPlugin.opts.publicPath).to.equal('/subdirectory/build/');
175173
// base path matches manifestKeyPrefix + trailing slash
176174
// the opening slash is kept, since the user is overriding this setting
177175
expect(manifestPlugin.opts.basePath).to.equal('/build/');
@@ -187,7 +185,6 @@ describe('The config-generator function', () => {
187185
const actualConfig = configGenerator(config);
188186

189187
const manifestPlugin = findPlugin(ManifestPlugin, actualConfig.plugins);
190-
expect(manifestPlugin.opts.publicPath).to.equal('/build/');
191188
expect(manifestPlugin.opts.basePath).to.equal('');
192189
});
193190
});

test/plugins/manifest.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'use strict';
1111

1212
const expect = require('chai').expect;
13-
const ManifestPlugin = require('../../lib/webpack/webpack-manifest-plugin');
13+
const ManifestPlugin = require('webpack-manifest-plugin');
1414
const WebpackConfig = require('../../lib/WebpackConfig');
1515
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
1616
const manifestPluginUtil = require('../../lib/plugins/manifest');
@@ -34,7 +34,6 @@ describe('plugins/manifest', () => {
3434
expect(plugins.length).to.equal(1);
3535
expect(plugins[0].plugin).to.be.instanceof(ManifestPlugin);
3636
expect(plugins[0].plugin.opts.fileName).to.equal('manifest.json');
37-
expect(plugins[0].plugin.opts.publicPath).to.equal('/foo/');
3837
});
3938

4039
it('with options callback', () => {
@@ -51,9 +50,6 @@ describe('plugins/manifest', () => {
5150

5251
// Allows to override default options
5352
expect(plugins[0].plugin.opts.fileName).to.equal('bar');
54-
55-
// Doesn't remove default options
56-
expect(plugins[0].plugin.opts.publicPath).to.equal('/foo/');
5753
});
5854

5955
it('with options callback that returns an object', () => {

yarn.lock

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44

55
"@types/node@*":
6-
version "9.6.4"
7-
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.4.tgz#0ef7b4cfc3499881c81e0ea1ce61a23f6f4f5b42"
6+
version "9.6.5"
7+
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.5.tgz#ee700810fdf49ac1c399fc5980b7559b3e5a381d"
88

99
"@types/tapable@^0":
1010
version "0.2.5"
@@ -1229,12 +1229,12 @@ caniuse-api@^1.5.2:
12291229
lodash.uniq "^4.5.0"
12301230

12311231
caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639:
1232-
version "1.0.30000828"
1233-
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000828.tgz#ed6d6f03b5a81fb291c3c0e088828b11a70948bf"
1232+
version "1.0.30000830"
1233+
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000830.tgz#6e45255b345649fd15ff59072da1e12bb3de2f13"
12341234

12351235
caniuse-lite@^1.0.30000792:
1236-
version "1.0.30000828"
1237-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000828.tgz#048f98de213f7a3c047bf78a9523c611855d4fdd"
1236+
version "1.0.30000830"
1237+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000830.tgz#cb96b8a2dd3cbfe04acea2af3c4e894249095328"
12381238

12391239
caseless@~0.11.0:
12401240
version "0.11.0"
@@ -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,12 @@ 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+
37593775
lazy-cache@^1.0.3:
37603776
version "1.0.4"
37613777
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
@@ -4238,6 +4254,10 @@ mute-stream@0.0.5:
42384254
version "0.0.5"
42394255
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0"
42404256

4257+
mutexify@1.0.1:
4258+
version "1.0.1"
4259+
resolved "https://registry.yarnpkg.com/mutexify/-/mutexify-1.0.1.tgz#9880206795d89e75efc1bcb4b4f52ebbd796e5e7"
4260+
42414261
nan@^2.10.0, nan@^2.3.0:
42424262
version "2.10.0"
42434263
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
@@ -6772,6 +6792,14 @@ webpack-dev-server@^2.4.5:
67726792
webpack-dev-middleware "1.12.2"
67736793
yargs "6.6.0"
67746794

6795+
webpack-manifest-plugin@v2.0.0-rc.1:
6796+
version "2.0.0-rc.1"
6797+
resolved "https://registry.yarnpkg.com/webpack-manifest-plugin/-/webpack-manifest-plugin-2.0.0-rc.1.tgz#82b03afd05a308a36a6066f1c37ac9ff1c9d5e8a"
6798+
dependencies:
6799+
fs-extra "^0.30.0"
6800+
lodash ">=3.5 <5"
6801+
mutexify "1.0.1"
6802+
67756803
webpack-notifier@^1.5.0:
67766804
version "1.6.0"
67776805
resolved "https://registry.yarnpkg.com/webpack-notifier/-/webpack-notifier-1.6.0.tgz#ffac8e55ff8c469752b8c1bbb011a16f10986e02"

0 commit comments

Comments
 (0)