Skip to content

Commit 8b4597c

Browse files
committed
fix(bundle): handle browser: true correctly
1 parent 304bcd3 commit 8b4597c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/compiler/app-core/bundle-app-core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export async function bundleApp(config: d.Config, compilerCtx: d.CompilerCtx, bu
3434
stencilBuildConditionalsPlugin(build, config.fsNamespace),
3535
globalScriptsPlugin(config, compilerCtx),
3636
componentEntryPlugin(config, compilerCtx, buildCtx, build, buildCtx.entryModules),
37+
config.sys.rollup.plugins.emptyJsResolver(),
3738
config.sys.rollup.plugins.commonjs({
3839
include: /node_modules/,
3940
sourceMap: false,
@@ -43,6 +44,7 @@ export async function bundleApp(config: d.Config, compilerCtx: d.CompilerCtx, bu
4344
pluginHelper(config, compilerCtx, buildCtx),
4445
config.sys.rollup.plugins.nodeResolve({
4546
mainFields: ['collection:main', 'jsnext:main', 'es2017', 'es2015', 'module', 'main'],
47+
browser: true,
4648
...config.nodeResolve
4749
}),
4850
bundleJson(config),

src/compiler/component-hydrate/bundle-hydrate-app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export async function bundleHydrateApp(config: d.Config, compilerCtx: d.Compiler
2727
stencilBuildConditionalsPlugin(build, config.fsNamespace),
2828
globalScriptsPlugin(config, compilerCtx),
2929
componentEntryPlugin(config, compilerCtx, buildCtx, build, buildCtx.entryModules),
30+
config.sys.rollup.plugins.emptyJsResolver(),
3031
config.sys.rollup.plugins.commonjs({
3132
include: /node_modules/,
3233
sourceMap: false,

src/sys/node/node-rollup.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ export const NodeRollup = {
1111
nodeResolve,
1212
replace,
1313
emptyJsResolver: () => {
14+
const emptyFile = path.resolve(__dirname, '../src/empty.js');
1415
return {
16+
resolveId(id: string) {
17+
if (id === emptyFile) {
18+
return id;
19+
}
20+
return null;
21+
},
1522
load(id: string) {
16-
if (id.endsWith('empty.js') && id.endsWith(path.join(__dirname, '../src/empty.js'))) {
23+
if (id === emptyFile) {
1724
return 'export default {};';
1825
}
1926
return null;

0 commit comments

Comments
 (0)