Skip to content

Commit b510cfe

Browse files
committed
feat: add hook for create sideEffects
1 parent 0c4ae7d commit b510cfe

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/pack/src/plugins/TypeScriptPlugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ type Options = {
1515
* A path to typescript config.
1616
*/
1717
configPath?: string
18+
19+
/**
20+
* A callback for when creating side effects.
21+
*/
22+
onCreateSideEffects: (path: string) => string[] | undefined
1823
}
1924

2025
class TypeScriptPlugin implements Plugin {
@@ -54,11 +59,17 @@ class TypeScriptPlugin implements Plugin {
5459
const moduleDirname = dirname(file)
5560
const esmModuleDirname = dirname(join('esm', file))
5661
const packageJsonPath = resolve(src, moduleDirname, 'package.json')
57-
const json: { sideEffects?: boolean | string[]; module?: string } = {
58-
// TODO: Side effects should be configurable.
62+
const json: { sideEffects: string[]; module?: string } = {
5963
sideEffects: ['*.css', '*@desktop.js', '*@touch-phone.js', '*@touch-pad.js'],
6064
}
6165

66+
if (this.options.onCreateSideEffects !== undefined) {
67+
const sideEffects = this.options.onCreateSideEffects(file)
68+
if (sideEffects !== undefined) {
69+
json.sideEffects = sideEffects
70+
}
71+
}
72+
6273
if (file.match(/^esm/) === null) {
6374
json.module = join(relative(moduleDirname, esmModuleDirname), 'index.js')
6475
}

0 commit comments

Comments
 (0)