Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create chunks for virtual modules when preserving modules
- Loading branch information
1 parent
dbbd52d
commit f505bfd
Showing
9 changed files
with
66 additions
and
17 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
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
36 changes: 36 additions & 0 deletions
36
test/function/samples/preserve-modules-virtual-modules/_config.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,36 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'Generates actual files for virtual modules when preserving modules', | ||
options: { | ||
input: ['main.js'], | ||
experimentalCodeSplitting: true, | ||
experimentalPreserveModules: true, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id === '\0virtualModule') return id; | ||
}, | ||
load(id) { | ||
if (id !== '\0virtualModule') return null; | ||
return 'export const virtual = "Virtual!";\n'; | ||
}, | ||
transform(code, id) { | ||
if (id === '\0virtualModule') return null; | ||
return 'import {virtual} from "\0virtualModule";\n' + code; | ||
} | ||
} | ||
] | ||
}, | ||
bundle(bundle) { | ||
return bundle | ||
.generate({ format: 'esm' }) | ||
.then(generated => | ||
assert.deepEqual(Object.keys(generated.output), [ | ||
'ROLLUP__virtualModule', | ||
'lib/lib.js', | ||
'main.js' | ||
]) | ||
); | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
test/function/samples/preserve-modules-virtual-modules/lib/lib.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 @@ | ||
assert.equal(virtual, 'Virtual!'); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/preserve-modules-virtual-modules/main.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,3 @@ | ||
import './lib/lib.js'; | ||
|
||
assert.equal(virtual, 'Virtual!'); |
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