Skip to content

Commit 2cf72e0

Browse files
committed
Making shared entry working with versioning
1 parent de9568d commit 2cf72e0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

lib/webpack/shared-entry-concat-plugin.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ function SharedEntryConcatPlugin(sharedEntryName, buildDir) {
1818
this.buildDir = buildDir;
1919
}
2020

21+
function getChunkFilename(stats, chunkName) {
22+
const chunk = stats.compilation.namedChunks.get(chunkName);
23+
24+
if (!chunk) {
25+
throw new Error(`Cannot find chunk ${chunkName}`);
26+
}
27+
28+
const jsFiles = chunk.files.filter(filename => {
29+
return /\.js$/.test(filename);
30+
});
31+
32+
if (jsFiles.length !== 1) {
33+
throw new Error(`Invalid number of files for chunk ${chunkName} - got ${jsFiles.join(', ')}`);
34+
}
35+
36+
return jsFiles[0];
37+
}
38+
2139
SharedEntryConcatPlugin.prototype.apply = function(compiler) {
2240
const done = (stats) => {
2341
if (stats.hasErrors()) {
@@ -41,8 +59,8 @@ SharedEntryConcatPlugin.prototype.apply = function(compiler) {
4159
* executed. This fixes that.
4260
*/
4361

44-
const sharedEntryOutputFile = path.join(this.buildDir, this.sharedEntryName + '.js');
45-
const tmpEntryBootstrapFile = path.join(this.buildDir, sharedEntryTmpName + '.js');
62+
const sharedEntryOutputFile = path.join(this.buildDir, getChunkFilename(stats, this.sharedEntryName));
63+
const tmpEntryBootstrapFile = path.join(this.buildDir, getChunkFilename(stats, sharedEntryTmpName));
4664

4765
if (!fs.existsSync(sharedEntryOutputFile)) {
4866
throw new Error(`Could not find shared entry output file: ${sharedEntryOutputFile}`);

test/functional.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,30 @@ describe('Functional tests using webpack', function() {
698698
});
699699
});
700700

701+
it('createdSharedEntry() works with versioning', (done) => {
702+
const config = createWebpackConfig('www/build', 'dev');
703+
config.setPublicPath('/build');
704+
config.addEntry('main', ['./js/no_require', './js/code_splitting', './js/arrow_function', './js/print_to_app']);
705+
config.addEntry('other', ['./js/no_require', './css/h1_style.css']);
706+
config.createSharedEntry('shared', './js/shared_example');
707+
config.enableVersioning();
708+
709+
testSetup.runWebpack(config, (webpackAssert) => {
710+
testSetup.requestTestPage(
711+
path.join(config.getContext(), 'www'),
712+
[
713+
convertToManifestPath('build/runtime.js', config),
714+
convertToManifestPath('build/shared.js', config),
715+
],
716+
(browser) => {
717+
// assert that the javascript brought into shared is executed
718+
browser.assert.text('#app', 'Welcome to Encore!');
719+
done();
720+
}
721+
);
722+
});
723+
});
724+
701725
it('in production mode, code is uglified', (done) => {
702726
const config = createWebpackConfig('www/build', 'production');
703727
config.setPublicPath('/build');

0 commit comments

Comments
 (0)