Skip to content

Commit c5f34fb

Browse files
huaijuliuxy0551
authored andcommitted
feat(ko): #180 expose babelIncludes option for ES2020+ packages
1 parent 51fb67b commit c5f34fb

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/ko/src/core/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Config {
6565
disableLazyImports: false,
6666
},
6767
autoPolyfills: false,
68+
babelIncludes: [],
6869
};
6970
}
7071
}

packages/ko/src/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ export type IOptions = {
6161
* @param {HookOptions[]}
6262
*/
6363
plugins?: HookOptions[];
64+
/**
65+
* Additional packages/paths to transpile via Babel, on top of ko's defaults.
66+
*
67+
* ko already transpiles these by default (they publish ES2020+ syntax):
68+
* - `immer`
69+
* - `react-grid-layout`
70+
* - `monaco-editor`
71+
* - internal `dt-common` source (`node_modules/dt-common/src/**`)
72+
*
73+
* You do not need to re-list them here. Use this to add your own
74+
* ES2020+ packages that ko doesn't know about. Entries are matched
75+
* as substring against the file path.
76+
*
77+
* @param {string[]}
78+
*/
79+
babelIncludes?: string[];
6480
/**
6581
* The path to the HTML template to use for the application.
6682
* @param {string}

packages/ko/src/webpack/loaders/script.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ class Script {
7676
return true;
7777
} else if (input.includes('monaco-editor')) {
7878
return true;
79-
} else if (input.includes('node_modules')) {
79+
}
80+
if (this.opts.babelIncludes?.some(item => item && input.includes(item))) {
81+
return true;
82+
}
83+
if (input.includes('node_modules')) {
8084
return false;
8185
} else {
8286
return true;

0 commit comments

Comments
 (0)