Skip to content

Commit 168d7d6

Browse files
committed
Fix an issue where base chunks without localized data, but with localized async chunks wouldn't correctly reference the async chunks.
1 parent ae2097e commit 168d7d6

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

build-tests/localization-plugin-test-01/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ module.exports = function(env) {
6969
}),
7070
new SetPublicPathPlugin({
7171
scriptName: {
72-
name: '[name]_[locale]_[contenthash].js',
73-
isTokenized: true
72+
useAssetName: true
7473
}
7574
}),
7675
new HtmlWebpackPlugin()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import(/* webpackChunkName: 'chunk-without-strings' */ './chunks/chunkWithoutStrings').then(({ ChunkWithoutStringsClass }) => {
2+
const chunk = new ChunkWithoutStringsClass();
3+
chunk.doStuff();
4+
});

build-tests/localization-plugin-test-03/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ module.exports = function(env) {
3131
entry: {
3232
'localization-test-A': path.join(__dirname, 'src', 'indexA.ts'),
3333
'localization-test-B': path.join(__dirname, 'src', 'indexB.ts'),
34-
'localization-test-C': path.join(__dirname, 'src', 'indexC.ts')
34+
'localization-test-C': path.join(__dirname, 'src', 'indexC.ts'),
35+
'localization-test-D': path.join(__dirname, 'src', 'indexD.ts')
3536
},
3637
output: {
3738
path: path.join(__dirname, 'dist'),

webpack/localization-plugin/src/LocalizationPlugin.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ export class LocalizationPlugin implements Webpack.Plugin {
166166
return;
167167
}
168168

169-
function tryInstallPreprocessor(): void {
170-
if (typingsPreprocessor) {
171-
compiler.hooks.beforeRun.tap(PLUGIN_NAME, () => typingsPreprocessor!.generateTypings());
172-
}
173-
}
174-
175169
if (isWebpackDevServer) {
176170
if (typingsPreprocessor) {
177171
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => typingsPreprocessor!.runWatcher());
@@ -185,7 +179,9 @@ export class LocalizationPlugin implements Webpack.Plugin {
185179

186180
WebpackConfigurationUpdater.amendWebpackConfigurationForInPlaceLocFiles(webpackConfigurationUpdaterOptions);
187181
} else {
188-
tryInstallPreprocessor();
182+
if (typingsPreprocessor) {
183+
compiler.hooks.beforeRun.tap(PLUGIN_NAME, () => typingsPreprocessor!.generateTypings());
184+
}
189185

190186
WebpackConfigurationUpdater.amendWebpackConfigurationForMultiLocale(webpackConfigurationUpdaterOptions);
191187

@@ -235,10 +231,9 @@ export class LocalizationPlugin implements Webpack.Plugin {
235231
return;
236232
}
237233

234+
// First pass - see if the chunk directly contains any loc modules
238235
for (const chunk of chunks) {
239-
let chunkHasAnyLocModules: boolean = Array.from(chunk.getAllAsyncChunks()).some(
240-
(asyncChunk) => EntityMarker.getMark(asyncChunk)
241-
);
236+
let chunkHasAnyLocModules: boolean = false;
242237
if (!chunkHasAnyLocModules) {
243238
for (const module of chunk.getModules()) {
244239
if (EntityMarker.getMark(module)) {
@@ -248,10 +243,24 @@ export class LocalizationPlugin implements Webpack.Plugin {
248243
}
249244
}
250245

251-
const replacementValue: string = chunkHasAnyLocModules
246+
EntityMarker.markEntity(chunk, chunkHasAnyLocModules);
247+
}
248+
249+
// Second pass - see if the chunk loads any localized chunks
250+
for (const chunk of chunks) {
251+
let localizedChunk: boolean = EntityMarker.getMark(chunk);
252+
if (
253+
!localizedChunk &&
254+
Array.from(chunk.getAllAsyncChunks()).some((asyncChunk) => EntityMarker.getMark(asyncChunk))
255+
) {
256+
localizedChunk = true;
257+
EntityMarker.markEntity(chunk, true);
258+
}
259+
260+
const replacementValue: string = localizedChunk
252261
? Constants.LOCALE_NAME_PLACEHOLDER
253262
: this._noStringsLocaleName;
254-
EntityMarker.markEntity(chunk, chunkHasAnyLocModules);
263+
EntityMarker.markEntity(chunk, localizedChunk);
255264
if (chunk.hasRuntime()) {
256265
chunk.filenameTemplate = (compilation.options.output!.filename as string).replace(
257266
Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX,

0 commit comments

Comments
 (0)