Skip to content

Commit c1bb2b3

Browse files
committed
Switch assets manifest plugin
1 parent c49793c commit c1bb2b3

File tree

4 files changed

+98
-123
lines changed

4 files changed

+98
-123
lines changed

assets/build/util/assetsPluginProcessOutput.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

assets/build/webpack.config.production.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,50 @@
1-
const AssetsPlugin = require('assets-webpack-plugin');
1+
'use strict'; // eslint-disable-line
2+
3+
const WebpackAssetsManifest = require('webpack-assets-manifest');
24
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
35
const cssnano = require('cssnano');
6+
const path = require('path');
47

5-
const processOutput = require('./util/assetsPluginProcessOutput');
68
const config = require('./config');
79

810
module.exports = {
911
plugins: [
10-
new AssetsPlugin({
11-
path: config.paths.dist,
12-
filename: 'assets.json',
13-
fullPath: false,
14-
processOutput(assets) {
15-
return JSON.stringify(Object.assign(processOutput(assets), config.manifest));
12+
new WebpackAssetsManifest({
13+
output: 'assets.json',
14+
space: 2,
15+
writeToDisk: false,
16+
assets: config.manifest,
17+
replacer(key, value) {
18+
if (typeof value === 'string') {
19+
return value;
20+
}
21+
const manifest = value;
22+
/**
23+
* Hack to prepend scripts/ or styles/ to manifest keys
24+
*
25+
* This might need to be reworked at some point.
26+
*
27+
* Before:
28+
* {
29+
* "main.js": "scripts/main_abcdef.js"
30+
* "main.css": "styles/main_abcdef.css"
31+
* }
32+
* After:
33+
* {
34+
* "scripts/main.js": "scripts/main_abcdef.js"
35+
* "styles/main.css": "styles/main_abcdef.css"
36+
* }
37+
*/
38+
Object.keys(manifest).forEach((src) => {
39+
const sourcePath = path.basename(path.dirname(src));
40+
const targetPath = path.basename(path.dirname(manifest[src]));
41+
if (sourcePath === targetPath) {
42+
return;
43+
}
44+
manifest[`${targetPath}/${src}`] = manifest[src];
45+
delete manifest[src];
46+
});
47+
return manifest;
1648
},
1749
}),
1850
new OptimizeCssAssetsPlugin({

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"node": ">= 4.5"
3030
},
3131
"devDependencies": {
32-
"assets-webpack-plugin": "^3.5.0",
33-
"autoprefixer": "^6.5.1",
32+
"autoprefixer": "^6.5.2",
3433
"body-parser": "^1.15.2",
3534
"browser-sync": "^2.17.5",
3635
"buble": "^0.14.2",
@@ -43,7 +42,7 @@
4342
"eslint-loader": "^1.6.1",
4443
"eslint-plugin-import": "^2.0.1",
4544
"eslint-plugin-jsx-a11y": "^2.2.3",
46-
"eslint-plugin-react": "^6.5.0",
45+
"eslint-plugin-react": "^6.6.0",
4746
"extract-text-webpack-plugin": "^2.0.0-beta.4",
4847
"file-loader": "^0.9.0",
4948
"glob": "^7.1.1",
@@ -65,6 +64,7 @@
6564
"style-loader": "^0.13.1",
6665
"url-loader": "^0.5.7",
6766
"webpack": "^2.1.0-beta.25",
67+
"webpack-assets-manifest": "^0.5.0",
6868
"webpack-dev-middleware": "^1.8.4",
6969
"webpack-hot-middleware": "^2.13.1"
7070
},

0 commit comments

Comments
 (0)