diff --git a/.changeset/twelve-impalas-remain.md b/.changeset/twelve-impalas-remain.md new file mode 100644 index 00000000..ca206a23 --- /dev/null +++ b/.changeset/twelve-impalas-remain.md @@ -0,0 +1,5 @@ +--- +'ko': patch +--- + +feat(ko): #180 expose babelIncludes option for ES2020+ packages diff --git a/packages/ko/src/core/config.ts b/packages/ko/src/core/config.ts index 927a1d90..587d9cec 100644 --- a/packages/ko/src/core/config.ts +++ b/packages/ko/src/core/config.ts @@ -65,6 +65,7 @@ class Config { disableLazyImports: false, }, autoPolyfills: false, + babelIncludes: [], }; } } diff --git a/packages/ko/src/types.ts b/packages/ko/src/types.ts index 2cc30dc1..d1aca242 100644 --- a/packages/ko/src/types.ts +++ b/packages/ko/src/types.ts @@ -61,6 +61,22 @@ export type IOptions = { * @param {HookOptions[]} */ plugins?: HookOptions[]; + /** + * Additional packages/paths to transpile via Babel, on top of ko's defaults. + * + * ko already transpiles these by default (they publish ES2020+ syntax): + * - `immer` + * - `react-grid-layout` + * - `monaco-editor` + * - internal `dt-common` source (`node_modules/dt-common/src/**`) + * + * You do not need to re-list them here. Use this to add your own + * ES2020+ packages that ko doesn't know about. Entries are matched + * as substring against the file path. + * + * @param {string[]} + */ + babelIncludes?: string[]; /** * The path to the HTML template to use for the application. * @param {string} diff --git a/packages/ko/src/webpack/loaders/script.ts b/packages/ko/src/webpack/loaders/script.ts index 4e3607b7..15f2bb32 100644 --- a/packages/ko/src/webpack/loaders/script.ts +++ b/packages/ko/src/webpack/loaders/script.ts @@ -76,7 +76,11 @@ class Script { return true; } else if (input.includes('monaco-editor')) { return true; - } else if (input.includes('node_modules')) { + } + if (this.opts.babelIncludes?.some(item => item && input.includes(item))) { + return true; + } + if (input.includes('node_modules')) { return false; } else { return true;