Skip to content

Commit

Permalink
junk: Kinda works but not really
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Aug 17, 2022
1 parent 92616af commit a8e740a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
22 changes: 20 additions & 2 deletions packages/cli/lib/lib/webpack/create-load-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ module.exports = (assets, namedChunkGroups, isProd) => {
*/
assets = JSON.parse(assets['asset-manifest.json']._value);

// Given a list of output chunks, we need some way to
// differentiate separate pages from an asynchronously loaded chunk.
//
// This (non-exhaustive) list is a best-guess attempt to do so.
const routePatterns = [
/^route-.*\.js$/,
/^routes-.*\.js$/,
/^page-.*\.js$/,
/^pages-.*\.js$/,
/^view-.*\.js$/,
/^views-.*\.js$/,
];

const mainJs = assets['bundle.js'];
const mainCss = assets['bundle.css'];

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

Object.keys(assets)
.filter(asset => /^route-.*\.js$/.test(asset))
.filter(asset => {
for (const pattern of routePatterns) {
if (pattern.test(asset)) return true;
}
return false;
})
.map(asset => asset.replace(/\.js$/, ''))
.forEach(route => {
const routeManifest = Object.assign({}, defaults);
Expand All @@ -43,7 +61,7 @@ module.exports = (assets, namedChunkGroups, isProd) => {
routeManifest[routeJs] = { type: 'script', weight: 0.9 };
if (routeCss) routeManifest[routeCss] = { type: 'script', weight: 0.9 };

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

if (namedChunkGroups) {
// async files to be loaded, generated by splitChunksPlugin
Expand Down
14 changes: 3 additions & 11 deletions packages/cli/lib/lib/webpack/webpack-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,9 @@ module.exports = function createBaseConfig(env) {
new MiniCssExtractPlugin({
filename:
isProd && !env.isServer ? '[name].[contenthash:5].css' : '[name].css',
chunkFilename: pathData => {
const chunkId = /** @type {string} */ (pathData.chunk.id);
const chunkName =
typeof chunkId === 'string'
? chunkId.split('_').slice(0, -1).join('-')
: chunkId;
return isProd
? `${chunkName}.chunk.[chunkhash:5].css`
: `${chunkName}.chunk.css`;
},
chunkFilename: isProd
? '[name].chunk.[contenthash:5].css'
: '[name].chunk.css',
}),
ProgressBarPlugin({
format:
Expand All @@ -328,7 +321,6 @@ module.exports = function createBaseConfig(env) {
},
},
}),
isProd && new webpack.LoaderOptionsPlugin({ minimize: true }),
new webpack.optimize.ModuleConcatenationPlugin(),

// strip out babel-helper invariant checks
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const cleanFilename = name =>
''
);

// TODO: Swap with the above when removing the async loader
const cleanFilename2 = name =>
(name = name.replace(/_/g, '-').replace(/(-index|-[jt]sx?$)/, ''));

/**
* @returns {Promise<import('webpack').Configuration>}
*/
Expand Down Expand Up @@ -89,11 +93,7 @@ async function clientConfig(env) {
return env.isProd ? '[name].[chunkhash:5].js' : '[name].js';
},
chunkFilename: pathData => {
const chunkId = /** @type {string} */ (pathData.chunk.id);
const chunkName =
typeof chunkId === 'string'
? chunkId.split('_').slice(0, -1).join('-')
: chunkId;
const chunkName = cleanFilename2(pathData.chunk.id);
return env.isProd
? `${chunkName}.chunk.[chunkhash:5].js`
: `${chunkName}.chunk.js`;
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/tests/images/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ exports.pushManifest = `
"type":"script",
"weight":1
},
"route-home.chunk.\\w{5}.js":{
"routes-home.chunk.\\w{5}.js":{
"type":"script",
"weight":0.9
},
"route-home.chunk.\\w{5}.css":{
"routes-home.chunk.\\w{5}.css":{
"type":"style",
"weight":0.9
}
Expand All @@ -238,11 +238,11 @@ exports.pushManifest = `
"type":"script",
"weight":1
},
"route-profile.chunk.\\w{5}.js":{
"routes-profile.chunk.\\w{5}.js":{
"type":"script",
"weight":0.9
},
"route-profile.chunk.\\w{5}.css":{
"routes-profile.chunk.\\w{5}.css":{
"type":"style",
"weight":0.9
}
Expand Down

0 comments on commit a8e740a

Please sign in to comment.