-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(builtin): do code splitting even if only one entry point
This separates handling of multiple entry points from code splitting
- Loading branch information
1 parent
d32d3a8
commit dc0133c
Showing
15 changed files
with
196 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 31 additions & 24 deletions
55
internal/e2e/rollup_code_splitting/additional_entry.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,62 @@ | ||
check = require('../check.js'); | ||
const fs = require('fs'); | ||
const expected = 'lib1 fn,dep3 fn,lib2 fn,dep2 fn'; | ||
const path = __dirname; | ||
const expected = 'dep4 fn'; | ||
const path = require('path'); | ||
|
||
describe('bundling chunks', () => { | ||
function findChunk() { | ||
let chunks = fs.readdirSync(path.join(__dirname, 'bundle_chunks')) | ||
.filter(name => name.startsWith('chunk-') && name.endsWith('.js')); | ||
if (chunks.length != 1) { | ||
fail('Not 1 chunk ' + chunks); | ||
} | ||
return chunks[0]; | ||
} | ||
|
||
describe('bundling additional entry point', () => { | ||
it('should work', () => { | ||
check(path, 'bundle.min.js', 'goldens/bundle.min.js_'); | ||
check(path, 'bundle.min.es2015.js', 'goldens/bundle.min.es2015.js_'); | ||
check(__dirname, 'bundle.min.js', 'goldens/bundle.min.js_'); | ||
check(__dirname, 'bundle.min.es2015.js', 'goldens/bundle.min.es2015.js_'); | ||
}); | ||
|
||
// Disabled because native ESModules can't be loaded in current nodejs | ||
// see https://github.com/bazelbuild/rules_nodejs/issues/593 | ||
xit('bundle_chunks_es6 should work', () => { | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/additional_entry.js'); | ||
const actual = (new additional_entry()).test(); | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/' + | ||
findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('bundle_chunks should work', () => { | ||
const additional_entry = | ||
require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/additional_entry.js') | ||
.default; | ||
const actual = (new additional_entry()).test(); | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/' + findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('bundle_chunks_min should work', () => { | ||
const additional_entry = | ||
require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/additional_entry.js') | ||
.default; | ||
const actual = (new additional_entry()).test(); | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/' + | ||
findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('bundle_chunks_min_debug should work', () => { | ||
const additional_entry = | ||
require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/additional_entry.js') | ||
.default; | ||
const actual = (new additional_entry()).test(); | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/' + | ||
findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should have a license header', () => { | ||
const content = fs.readFileSync( | ||
require.resolve( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/additional_entry.js'), | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/' + | ||
findChunk()), | ||
{encoding: 'utf-8'}); | ||
expect(content).toContain('dummy license banner'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
check = require('../check.js'); | ||
const fs = require('fs'); | ||
const expected = 'dep4 fn'; | ||
const path = require('path'); | ||
|
||
describe('code splitting', () => { | ||
function findChunk() { | ||
let chunks = fs.readdirSync(path.join(__dirname, 'bundle_chunks')) | ||
.filter(name => name.startsWith('chunk-') && name.endsWith('.js')); | ||
if (chunks.length != 1) { | ||
fail('Not 1 chunk ' + chunks); | ||
} | ||
return chunks[0]; | ||
} | ||
|
||
it('should work', () => { | ||
check(__dirname, 'bundle.min.js', 'goldens/bundle.min.js_'); | ||
check(__dirname, 'bundle.min.es2015.js', 'goldens/bundle.min.es2015.js_'); | ||
check(__dirname, 'bundle_multi_entry.min.js', 'goldens/bundle_multi_entry.min.js_'); | ||
}); | ||
|
||
// Disabled because native ESModules can't be loaded in current nodejs | ||
// see https://github.com/bazelbuild/rules_nodejs/issues/593 | ||
xit('bundle_chunks_es6 should work', () => { | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/' + | ||
findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('bundle_chunks should work', () => { | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/' + findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('bundle_chunks_min should work', () => { | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/' + | ||
findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('bundle_chunks_min_debug should work', () => { | ||
const additional_entry = require( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/' + | ||
findChunk()); | ||
const actual = additional_entry.fn(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should have a license header', () => { | ||
const content = fs.readFileSync( | ||
require.resolve( | ||
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/' + | ||
findChunk()), | ||
{encoding: 'utf-8'}); | ||
expect(content).toContain('dummy license banner'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export function fn() { | ||
return 'dep4 fn'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ export function dynamic() { | |
return import('./dep4.js').then(dep4 => { | ||
return dep4.fn(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
internal/e2e/rollup_code_splitting/goldens/bundle_multi_entry.min.js_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SystemJS boilerplate/entry point TEMPLATE for code-split rollup_bundle. | ||
// GENERATED BY Bazel | ||
(function(global) { | ||
System.config({ | ||
packages: { | ||
'': {map: {"./main1": "bundle_multi_entry_chunks_min/main1", "./additional_entry.js": "bundle_multi_entry_chunks_min/additional_entry.js"}, defaultExtension: 'js'}, | ||
} | ||
}); | ||
System.import('main1.js').catch(function(err) { | ||
console.error(err); | ||
}); | ||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.