Skip to content

Commit a8e740a

Browse files
committed
junk: Kinda works but not really
1 parent 92616af commit a8e740a

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

packages/cli/lib/lib/webpack/create-load-manifest.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ module.exports = (assets, namedChunkGroups, isProd) => {
1010
*/
1111
assets = JSON.parse(assets['asset-manifest.json']._value);
1212

13+
// Given a list of output chunks, we need some way to
14+
// differentiate separate pages from an asynchronously loaded chunk.
15+
//
16+
// This (non-exhaustive) list is a best-guess attempt to do so.
17+
const routePatterns = [
18+
/^route-.*\.js$/,
19+
/^routes-.*\.js$/,
20+
/^page-.*\.js$/,
21+
/^pages-.*\.js$/,
22+
/^view-.*\.js$/,
23+
/^views-.*\.js$/,
24+
];
25+
1326
const mainJs = assets['bundle.js'];
1427
const mainCss = assets['bundle.css'];
1528

@@ -32,7 +45,12 @@ module.exports = (assets, namedChunkGroups, isProd) => {
3245
};
3346

3447
Object.keys(assets)
35-
.filter(asset => /^route-.*\.js$/.test(asset))
48+
.filter(asset => {
49+
for (const pattern of routePatterns) {
50+
if (pattern.test(asset)) return true;
51+
}
52+
return false;
53+
})
3654
.map(asset => asset.replace(/\.js$/, ''))
3755
.forEach(route => {
3856
const routeManifest = Object.assign({}, defaults);
@@ -43,7 +61,7 @@ module.exports = (assets, namedChunkGroups, isProd) => {
4361
routeManifest[routeJs] = { type: 'script', weight: 0.9 };
4462
if (routeCss) routeManifest[routeCss] = { type: 'script', weight: 0.9 };
4563

46-
const path = route.replace(/^route-/, '/').replace(/^\/home/, '/');
64+
const path = route.replace(/^.*-/, '/').replace(/^\/home/, '/');
4765

4866
if (namedChunkGroups) {
4967
// async files to be loaded, generated by splitChunksPlugin

packages/cli/lib/lib/webpack/webpack-base-config.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,9 @@ module.exports = function createBaseConfig(env) {
292292
new MiniCssExtractPlugin({
293293
filename:
294294
isProd && !env.isServer ? '[name].[contenthash:5].css' : '[name].css',
295-
chunkFilename: pathData => {
296-
const chunkId = /** @type {string} */ (pathData.chunk.id);
297-
const chunkName =
298-
typeof chunkId === 'string'
299-
? chunkId.split('_').slice(0, -1).join('-')
300-
: chunkId;
301-
return isProd
302-
? `${chunkName}.chunk.[chunkhash:5].css`
303-
: `${chunkName}.chunk.css`;
304-
},
295+
chunkFilename: isProd
296+
? '[name].chunk.[contenthash:5].css'
297+
: '[name].chunk.css',
305298
}),
306299
ProgressBarPlugin({
307300
format:
@@ -328,7 +321,6 @@ module.exports = function createBaseConfig(env) {
328321
},
329322
},
330323
}),
331-
isProd && new webpack.LoaderOptionsPlugin({ minimize: true }),
332324
new webpack.optimize.ModuleConcatenationPlugin(),
333325

334326
// strip out babel-helper invariant checks

packages/cli/lib/lib/webpack/webpack-client-config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const cleanFilename = name =>
2424
''
2525
);
2626

27+
// TODO: Swap with the above when removing the async loader
28+
const cleanFilename2 = name =>
29+
(name = name.replace(/_/g, '-').replace(/(-index|-[jt]sx?$)/, ''));
30+
2731
/**
2832
* @returns {Promise<import('webpack').Configuration>}
2933
*/
@@ -89,11 +93,7 @@ async function clientConfig(env) {
8993
return env.isProd ? '[name].[chunkhash:5].js' : '[name].js';
9094
},
9195
chunkFilename: pathData => {
92-
const chunkId = /** @type {string} */ (pathData.chunk.id);
93-
const chunkName =
94-
typeof chunkId === 'string'
95-
? chunkId.split('_').slice(0, -1).join('-')
96-
: chunkId;
96+
const chunkName = cleanFilename2(pathData.chunk.id);
9797
return env.isProd
9898
? `${chunkName}.chunk.[chunkhash:5].js`
9999
: `${chunkName}.chunk.js`;

packages/cli/tests/images/build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ exports.pushManifest = `
220220
"type":"script",
221221
"weight":1
222222
},
223-
"route-home.chunk.\\w{5}.js":{
223+
"routes-home.chunk.\\w{5}.js":{
224224
"type":"script",
225225
"weight":0.9
226226
},
227-
"route-home.chunk.\\w{5}.css":{
227+
"routes-home.chunk.\\w{5}.css":{
228228
"type":"style",
229229
"weight":0.9
230230
}
@@ -238,11 +238,11 @@ exports.pushManifest = `
238238
"type":"script",
239239
"weight":1
240240
},
241-
"route-profile.chunk.\\w{5}.js":{
241+
"routes-profile.chunk.\\w{5}.js":{
242242
"type":"script",
243243
"weight":0.9
244244
},
245-
"route-profile.chunk.\\w{5}.css":{
245+
"routes-profile.chunk.\\w{5}.css":{
246246
"type":"style",
247247
"weight":0.9
248248
}

0 commit comments

Comments
 (0)