Skip to content

Commit

Permalink
enhance: Improve chunk naming during analyze and nohash
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Apr 14, 2021
1 parent ae464d8 commit 7293214
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"release": "lerna publish",
"build": "lerna run build --stream",
"build:sizecompare": "yarn workspace anansi-example-typescript build --env nohash",
"build:sizecompare": "yarn workspace anansi-example-typescript build:clean && yarn workspace anansi-example-typescript build --env nohash",
"prepare": "husky install && yarn lerna run build --ignore anansi-example-linaria --ignore anansi-example-typescript"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions packages/webpack-config-anansi/src/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function makeBaseConfig({
extraJsLoaders,
linariaOptions,
tsconfigPathsOptions,
env,
nohash,
argv,
}) {
const babelLoader = generateBabelLoader({
Expand Down Expand Up @@ -60,8 +60,8 @@ export default function makeBaseConfig({
output: {
path: path.join(rootPath, buildDir),
publicPath: WEBPACK_PUBLIC_HOST + WEBPACK_PUBLIC_PATH,
filename: env?.nohash ? '[name].js' : '[name]-[contenthash].js',
chunkFilename: env?.nohash ? '[name].chunk.js' : '[name]-[contenthash].chunk.js',
filename: nohash ? '[name].js' : '[name]-[contenthash].js',
chunkFilename: nohash ? '[name].chunk.js' : '[name]-[contenthash].chunk.js',
globalObject: "(typeof self !== 'undefined' ? self : this)",
},
cache: {
Expand All @@ -81,9 +81,9 @@ export default function makeBaseConfig({
}),
new MiniCssExtractPlugin({
filename:
mode !== 'production' | env?.nohash ? '[name].css' : '[name].[contenthash].css',
mode !== 'production' | nohash ? '[name].css' : '[name].[contenthash].css',
chunkFilename:
mode !== 'production' | env?.nohash ? '[name].css' : '[name].[contenthash].css',
mode !== 'production' | nohash ? '[name].css' : '[name].[contenthash].css',
}),
],
module: {
Expand Down Expand Up @@ -142,7 +142,7 @@ export default function makeBaseConfig({
{
loader: require.resolve('file-loader'),
options: {
name: env?.nohash
name: nohash
? '[name].[ext]'
: mode === 'production'
? '[name].[contenthash].[ext]'
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-config-anansi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function makeConfig(options) {
extraJsLoaders: [],
...options,
mode: argv?.mode || process.env.NODE_ENV,
nohash: env?.nohash ?? env?.analyze ?? process.env.WEBPACK_ANALYZE === 'true',
argv,
env,
};
Expand Down
4 changes: 4 additions & 0 deletions packages/webpack-config-anansi/src/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function makeProdConfig(
cssModulesOptions,
fontPreload,
svgoOptions,
nohash,
},
) {
const config = { ...baseConfig };
Expand Down Expand Up @@ -118,6 +119,9 @@ export default function makeProdConfig(
name: 'webpack-runtime',
},
};
if (nohash) {
config.optimization.chunkIds = 'named';
}
if (!env.readable) {
config.optimization.minimizer = [
new TerserPlugin({
Expand Down

0 comments on commit 7293214

Please sign in to comment.