Skip to content

Commit

Permalink
Revert "experiment: preserve modules (#306)"
Browse files Browse the repository at this point in the history
This reverts commit 6c563bc.
  • Loading branch information
CodyJasonBennett committed Oct 17, 2023
1 parent 6c563bc commit 8119d7d
Show file tree
Hide file tree
Showing 4 changed files with 426 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
run: yarn build
- name: Check for SSR compat
run: node dist/index.cjs && node dist/index.js
- name: Check tree-shaking
run: npx agadoo@latest dist/index.js
- name: Check NPM config
run: npx publint@latest dist
release:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
},
"sideEffects": false,
"devDependencies": {
"@babel/core": "^7.22.20",
"@types/babel__core": "^7.20.2",
"@types/node": "^20.6.3",
"@types/three": "^0.128.0",
"copyfiles": "^2.4.1",
Expand Down
31 changes: 28 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'node:path'
import * as babel from '@babel/core'
import { defineConfig } from 'vite'

export default defineConfig({
Expand All @@ -13,9 +14,33 @@ export default defineConfig({
},
rollupOptions: {
external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),
output: {
preserveModules: true,
},
},
},
plugins: [
{
name: 'vite-tree-shake',
renderChunk: {
order: 'post',
async handler(code) {
function annotate(path: babel.NodePath): void {
if (!path.getFunctionParent()) {
path.addComment('leading', '@__PURE__')
}
}

return babel.transform(code, {
sourceMaps: true,
plugins: [
{
visitor: {
CallExpression: annotate,
NewExpression: annotate,
},
},
],
}) as any
},
},
},
],
})
Loading

0 comments on commit 8119d7d

Please sign in to comment.