Skip to content

Commit

Permalink
don't rely on chunk name stability
Browse files Browse the repository at this point in the history
Instead of trying to make all entry chunk names stable, we'll make sure we clean up stale ones before we append them into vendor.js.
  • Loading branch information
ef4 committed Mar 24, 2021
1 parent 6c43934 commit 9447c38
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
10 changes: 2 additions & 8 deletions packages/ember-auto-import/ts/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export interface BundlerHook {
export default class Bundler extends Plugin {
private lastDeps: Map<string, BundleDependencies> | undefined;
private cachedBundlerHook: BundlerHook | undefined;
private didEnsureDirs: boolean;
private options: BundlerPluginOptions;
private isWatchingSomeDeps: boolean;

Expand All @@ -46,7 +45,6 @@ export default class Bundler extends Plugin {
needsCache: true,
});
this.options = options;
this.didEnsureDirs = false;
this.isWatchingSomeDeps = deps.length > 1;
}

Expand Down Expand Up @@ -107,27 +105,23 @@ export default class Bundler extends Plugin {
}

async build() {
this.ensureDirs();
reloadDevPackages();
let { splitter } = this.options;
let bundleDeps = await splitter.deps();
if (bundleDeps !== this.lastDeps || this.isWatchingSomeDeps) {
let buildResult = await this.bundlerHook.build(bundleDeps);
this.emptyDirs();
this.addEntrypoints(buildResult);
this.addLazyAssets(buildResult);
this.lastDeps = bundleDeps;
}
}

private ensureDirs() {
if (this.didEnsureDirs) {
return;
}
private emptyDirs() {
emptyDirSync(join(this.outputPath, 'lazy'));
for (let bundle of this.options.bundles.names) {
emptyDirSync(join(this.outputPath, 'entrypoints', bundle));
}
this.didEnsureDirs = true;
}

private addEntrypoints({ entrypoints, dir }: BuildResult) {
Expand Down
10 changes: 1 addition & 9 deletions packages/ember-auto-import/ts/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,14 @@ export default class WebpackBundler implements BundlerHook {
},
output: {
path: this.outputDir,
// entry chunks need to have stable names, so we can more easily gather
// them all up to append to Ember's vendor.js
filename: `chunk.[id].js`,
filename: `chunk.[id].[chunkhash].js`,
chunkFilename: `chunk.[id].[chunkhash].js`,
libraryTarget: 'var',
library: '__ember_auto_import__',
},
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
// similar to above, entry vendor chunks need to have stable names
vendors: {
filename: 'chunk.[name].js',
} as any, // typings are missing a valid documented option
},
},
},
resolveLoader: {
Expand Down
4 changes: 2 additions & 2 deletions test-scenarios/common-chunk-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ appScenarios
module('Unit | common chunk', function () {
test('can use two dynamic imports that share a common chunk', async function(assert) {
assert.equal(await useLeft(), 'The message is left');
assert.equal(await useRight(), 'The message is right');
assert.equal(await useLeft(), 'the message is left');
assert.equal(await useRight(), 'the message is right');
});
});
`,
Expand Down

0 comments on commit 9447c38

Please sign in to comment.