Skip to content

Commit 94e65e7

Browse files
committed
minor #410 Implement assets webpack plugin (codayblue)
This PR was merged into the master branch. Discussion ---------- Implement assets webpack plugin This should solve issue #408 because it implements the plugin that was requested to be looked into. The changes that have happened by implementing this plugin is that the keys might not be in the file for a given entry. So lets say we have a main entry point that has JavaScript but no CSS, the CSS key will not be under that entry point. The other issue is that when a file type only has one file of a given file type it will not be in an array in the entrypoints.json file it will just be a string value linked to the property. Commits ------- 2f106e8 First iteration of of assets-webpack-plugin
2 parents 309e575 + 2f106e8 commit 94e65e7

File tree

6 files changed

+75
-169
lines changed

6 files changed

+75
-169
lines changed

lib/plugins/entry-files-manifest.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,46 @@
99

1010
'use strict';
1111

12-
const EntryFilesManifestPlugin = require('../webpack/entry-files-manifest-plugin');
1312
const PluginPriorities = require('./plugin-priorities');
14-
const path = require('path');
1513
const sharedEntryTmpName = require('../utils/sharedEntryTmpName');
1614
const copyEntryTmpName = require('../utils/copyEntryTmpName');
17-
const manifestKeyPrefixHelper = require('../utils/manifest-key-prefix-helper');
15+
const AssetsPlugin = require('assets-webpack-plugin');
16+
17+
function processOutput(assets) {
18+
if (assets.hasOwnProperty(copyEntryTmpName)) {
19+
delete assets[copyEntryTmpName];
20+
}
21+
if (assets.hasOwnProperty(sharedEntryTmpName)) {
22+
delete assets[sharedEntryTmpName];
23+
}
24+
// This will iterate over all the entry points and remove the / from the start of the paths. It also converts the
25+
// one file entries into an array of one entry since that was how the entry point file was before this change.
26+
for (const asset in assets) {
27+
for (const fileType in assets[asset]) {
28+
if (Array.isArray(assets[asset][fileType])) {
29+
assets[asset][fileType] = assets[asset][fileType].map(buildPath => buildPath.replace(/^\//g, ''));
30+
} else {
31+
assets[asset][fileType] = [assets[asset][fileType].replace(/^\//g, '')];
32+
}
33+
}
34+
}
35+
return JSON.stringify(assets);
36+
}
1837

1938
/**
2039
* @param {Array} plugins
2140
* @param {WebpackConfig} webpackConfig
2241
* @return {void}
2342
*/
2443
module.exports = function(plugins, webpackConfig) {
25-
2644
plugins.push({
27-
plugin: new EntryFilesManifestPlugin(
28-
path.join(webpackConfig.outputPath, 'entrypoints.json'),
29-
manifestKeyPrefixHelper(webpackConfig),
30-
[sharedEntryTmpName, copyEntryTmpName],
31-
webpackConfig.styleEntries
32-
),
33-
priority: PluginPriorities.EntryFilesManifestPlugin
45+
plugin: new AssetsPlugin({
46+
path: webpackConfig.outputPath,
47+
filename: 'entrypoints.json',
48+
includeAllFileTypes: true,
49+
entrypoints: true,
50+
processOutput: processOutput
51+
}),
52+
priority: PluginPriorities.AssetsPlugin
3453
});
3554
};

lib/plugins/plugin-priorities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ module.exports = {
2525
SharedEntryContactPlugin: 20,
2626
ForkTsCheckerWebpackPlugin: 10,
2727
HashedModuleIdsPlugin: 0,
28-
EntryFilesManifestPlugin: -10,
28+
AssetsPlugin: -10,
2929
};

lib/webpack/entry-files-manifest-plugin.js

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@babel/core": "^7.0.0",
2929
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
3030
"@babel/preset-env": "^7.0.0",
31+
"assets-webpack-plugin": "^3.9.7",
3132
"babel-loader": "^8.0.0",
3233
"chalk": "^2.4.1",
3334
"clean-webpack-plugin": "^0.1.19",

test/functional.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,14 @@ describe('Functional tests using webpack', function() {
103103

104104
webpackAssert.assertOutputJsonFileMatches('entrypoints.json', {
105105
main: {
106-
js: ['build/runtime.js', 'build/main.js'],
107-
css: []
106+
js: ['build/runtime.js', 'build/main.js']
108107
},
109108
font: {
110-
// no runtime for style entries
111-
js: [],
109+
js: ['build/runtime.js'],
112110
css: ['build/font.css']
113111
},
114112
bg: {
115-
js: [],
113+
js: ['build/runtime.js'],
116114
css: ['build/bg.css']
117115
},
118116
});
@@ -1608,7 +1606,6 @@ module.exports = {
16081606
config.addEntry('other', ['./css/roboto_font.css', 'vue']);
16091607
config.setPublicPath('/build');
16101608
// enable versioning to make sure entrypoints.json is not affected
1611-
config.enableVersioning();
16121609
config.splitEntryChunks();
16131610
config.configureSplitChunks((splitChunks) => {
16141611
splitChunks.minSize = 0;
@@ -1633,7 +1630,7 @@ module.exports = {
16331630
});
16341631
});
16351632

1636-
it('Custom public path does affect entrypoints.json or manifest.json', (done) => {
1633+
it('Custom public path does affect entrypoints.json but does not affect manifest.json', (done) => {
16371634
const config = createWebpackConfig('web/build', 'dev');
16381635
config.addEntry('main', ['./css/roboto_font.css', './js/no_require', 'vue']);
16391636
config.addEntry('other', ['./css/roboto_font.css', 'vue']);
@@ -1647,12 +1644,22 @@ module.exports = {
16471644
testSetup.runWebpack(config, (webpackAssert) => {
16481645
webpackAssert.assertOutputJsonFileMatches('entrypoints.json', {
16491646
main: {
1650-
js: ['custom_prefix/runtime.js', 'custom_prefix/vendors~main~other.js', 'custom_prefix/main~other.js', 'custom_prefix/main.js'],
1651-
css: ['custom_prefix/main~other.css']
1647+
js: [
1648+
'http://localhost:8080/build/runtime.js',
1649+
'http://localhost:8080/build/vendors~main~other.js',
1650+
'http://localhost:8080/build/main~other.js',
1651+
'http://localhost:8080/build/main.js'
1652+
],
1653+
css: ['http://localhost:8080/build/main~other.css']
16521654
},
16531655
other: {
1654-
js: ['custom_prefix/runtime.js', 'custom_prefix/vendors~main~other.js', 'custom_prefix/main~other.js', 'custom_prefix/other.js'],
1655-
css: ['custom_prefix/main~other.css']
1656+
js: [
1657+
'http://localhost:8080/build/runtime.js',
1658+
'http://localhost:8080/build/vendors~main~other.js',
1659+
'http://localhost:8080/build/main~other.js',
1660+
'http://localhost:8080/build/other.js'
1661+
],
1662+
css: ['http://localhost:8080/build/main~other.css']
16561663
},
16571664
});
16581665

@@ -1698,8 +1705,6 @@ module.exports = {
16981705
config.addEntry('main', ['./js/code_splitting', 'vue']);
16991706
config.addEntry('other', ['./js/no_require', 'vue']);
17001707
config.setPublicPath('/build');
1701-
// enable versioning to make sure entrypoints.json is not affected
1702-
config.enableVersioning();
17031708
config.splitEntryChunks();
17041709
config.configureSplitChunks((splitChunks) => {
17051710
splitChunks.minSize = 0;
@@ -1708,20 +1713,18 @@ module.exports = {
17081713
testSetup.runWebpack(config, (webpackAssert) => {
17091714
webpackAssert.assertOutputJsonFileMatches('entrypoints.json', {
17101715
main: {
1711-
js: ['build/runtime.js', 'build/vendors~main~other.js', 'build/main.js'],
1712-
css: []
1716+
js: ['build/runtime.js', 'build/vendors~main~other.js', 'build/main.js']
17131717
},
17141718
other: {
17151719
// the 0.[hash].js is because the "no_require" module was already split to this
17161720
// so, it has that filename, instead of following the normal pattern
1717-
js: ['build/runtime.js', 'build/vendors~main~other.js', 'build/0.f1e0a935.js', 'build/other.js'],
1718-
css: []
1721+
js: ['build/runtime.js', 'build/vendors~main~other.js', 'build/0.js', 'build/other.js']
17191722
},
17201723
});
17211724

17221725
// make split chunks are correct in manifest
17231726
webpackAssert.assertManifestKeyExists('build/vendors~main~other.js');
1724-
webpackAssert.assertManifestKeyExists('build/0.f1e0a935.js');
1727+
webpackAssert.assertManifestKeyExists('build/0.js');
17251728

17261729
done();
17271730
});

yarn.lock

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,17 @@ assertion-error@^1.0.1:
12381238
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
12391239
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==
12401240

1241+
assets-webpack-plugin@^3.9.7:
1242+
version "3.9.7"
1243+
resolved "https://registry.yarnpkg.com/assets-webpack-plugin/-/assets-webpack-plugin-3.9.7.tgz#0c3c13632cc4490b2ef79fd0bbb16c69a724f364"
1244+
integrity sha512-yxo4MlSb++B88qQFE27Wf56ykGaDHZeKcSbrstSFOOwOxv33gWXtM49+yfYPSErlXPAMT5lVy3YPIhWlIFjYQw==
1245+
dependencies:
1246+
camelcase "^5.0.0"
1247+
escape-string-regexp "^1.0.3"
1248+
lodash.assign "^4.2.0"
1249+
lodash.merge "^4.6.1"
1250+
mkdirp "^0.5.1"
1251+
12411252
assign-symbols@^1.0.0:
12421253
version "1.0.0"
12431254
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
@@ -1719,6 +1730,11 @@ camelcase@^4.1.0:
17191730
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
17201731
integrity sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=
17211732

1733+
camelcase@^5.0.0:
1734+
version "5.0.0"
1735+
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.0.0.tgz#03295527d58bd3cd4aa75363f35b2e8d97be2f42"
1736+
integrity sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA==
1737+
17221738
caniuse-api@^1.5.2:
17231739
version "1.6.1"
17241740
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-1.6.1.tgz#b534e7c734c4f81ec5fbe8aca2ad24354b962c6c"
@@ -2894,7 +2910,7 @@ escape-html@~1.0.3:
28942910
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
28952911
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
28962912

2897-
[email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
2913+
[email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.3, escape-string-regexp@^1.0.5:
28982914
version "1.0.5"
28992915
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
29002916
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
@@ -5016,6 +5032,11 @@ lodash.memoize@^4.1.2:
50165032
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
50175033
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
50185034

5035+
lodash.merge@^4.6.1:
5036+
version "4.6.1"
5037+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"
5038+
integrity sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ==
5039+
50195040
lodash.mergewith@^4.6.0:
50205041
version "4.6.1"
50215042
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927"

0 commit comments

Comments
 (0)