Skip to content

Commit

Permalink
experiment: preserve modules (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett authored Oct 17, 2023
1 parent f58eee2 commit 6c563bc
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 426 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ 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: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
},
"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: 3 additions & 28 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as path from 'node:path'
import * as babel from '@babel/core'
import { defineConfig } from 'vite'

export default defineConfig({
Expand All @@ -14,33 +13,9 @@ export default defineConfig({
},
rollupOptions: {
external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),
},
},
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
},
output: {
preserveModules: true,
},
},
],
},
})
Loading

0 comments on commit 6c563bc

Please sign in to comment.