Skip to content

Commit 8119d7d

Browse files
Revert "experiment: preserve modules (#306)"
This reverts commit 6c563bc.
1 parent 6c563bc commit 8119d7d

File tree

4 files changed

+426
-3
lines changed

4 files changed

+426
-3
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
run: yarn build
2929
- name: Check for SSR compat
3030
run: node dist/index.cjs && node dist/index.js
31+
- name: Check tree-shaking
32+
run: npx agadoo@latest dist/index.js
3133
- name: Check NPM config
3234
run: npx publint@latest dist
3335
release:

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
},
3737
"sideEffects": false,
3838
"devDependencies": {
39+
"@babel/core": "^7.22.20",
40+
"@types/babel__core": "^7.20.2",
3941
"@types/node": "^20.6.3",
4042
"@types/three": "^0.128.0",
4143
"copyfiles": "^2.4.1",

vite.config.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'node:path'
2+
import * as babel from '@babel/core'
23
import { defineConfig } from 'vite'
34

45
export default defineConfig({
@@ -13,9 +14,33 @@ export default defineConfig({
1314
},
1415
rollupOptions: {
1516
external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),
16-
output: {
17-
preserveModules: true,
18-
},
1917
},
2018
},
19+
plugins: [
20+
{
21+
name: 'vite-tree-shake',
22+
renderChunk: {
23+
order: 'post',
24+
async handler(code) {
25+
function annotate(path: babel.NodePath): void {
26+
if (!path.getFunctionParent()) {
27+
path.addComment('leading', '@__PURE__')
28+
}
29+
}
30+
31+
return babel.transform(code, {
32+
sourceMaps: true,
33+
plugins: [
34+
{
35+
visitor: {
36+
CallExpression: annotate,
37+
NewExpression: annotate,
38+
},
39+
},
40+
],
41+
}) as any
42+
},
43+
},
44+
},
45+
],
2146
})

0 commit comments

Comments
 (0)