Skip to content

Commit c78fe51

Browse files
committed
fix(bundling): fix bundling node resolved import when using browser entry
Closes #1185
1 parent 96736e3 commit c78fe51

4 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/compiler/app/app-global-scripts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ async function bundleProjectGlobal(config: Config, compilerCtx: CompilerCtx, bui
9595
jsnext: true,
9696
main: true
9797
}),
98+
config.sys.rollup.plugins.emptyJsResolver(),
9899
config.sys.rollup.plugins.commonjs({
99100
include: 'node_modules/**',
100101
sourceMap: false

src/compiler/bundle/rollup-bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export async function createBundle(config: d.Config, compilerCtx: d.CompilerCtx,
5858
values: replaceObj
5959
}),
6060
config.sys.rollup.plugins.nodeResolve(nodeResolveConfig),
61+
config.sys.rollup.plugins.emptyJsResolver(),
6162
config.sys.rollup.plugins.commonjs(commonjsConfig),
6263
bundleJson(config),
6364
inMemoryFsRead(config, compilerCtx, buildCtx, entryModules),

src/declarations/system.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ export interface StencilSystem {
3737
path?: Path;
3838
requestLatestCompilerVersion?(): Promise<string>;
3939
resolveModule?(fromDir: string, moduleId: string): string;
40-
rollup?: {
41-
rollup: {
42-
(config: any): Promise<any>;
43-
};
44-
plugins: {[pluginName: string]: any};
45-
};
40+
rollup?: RollupInterface;
4641
scopeCss?: (cssText: string, scopeId: string, hostScopeId: string, slotScopeId: string) => Promise<string>;
4742
semver?: Semver;
4843
storage?: Storage;
@@ -60,6 +55,18 @@ export interface StencilSystem {
6055
}
6156

6257

58+
export interface RollupInterface {
59+
rollup: {
60+
(config: any): Promise<any>;
61+
};
62+
plugins: {
63+
nodeResolve(opts: any): any;
64+
emptyJsResolver(): any;
65+
commonjs(opts: any): any;
66+
};
67+
}
68+
69+
6370
export interface Semver {
6471
lt(v1: string, v2: string): boolean;
6572
lte(v1: string, v2: string): boolean;

src/sys/node/node-rollup.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import { rollup } from 'rollup';
22
import commonjs from 'rollup-plugin-commonjs';
33
import nodeResolve from 'rollup-plugin-node-resolve';
4+
import path from 'path';
45

56

67
export const NodeRollup = {
78
rollup,
89
plugins: {
910
commonjs,
10-
nodeResolve
11+
nodeResolve,
12+
emptyJsResolver: () => {
13+
return {
14+
load(id: string) {
15+
if (id.endsWith('empty.js') && id.endsWith(path.join(__dirname, '../src/empty.js'))) {
16+
return 'export default {};';
17+
}
18+
return null;
19+
}
20+
};
21+
}
1122
}
1223
};

0 commit comments

Comments
 (0)