Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 1ea2171

Browse files
committed
feat: vite and webpack plugin
1 parent cfdf869 commit 1ea2171

File tree

8 files changed

+405
-19
lines changed

8 files changed

+405
-19
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Bring `<script setup>` to Vue 2
1010
- [x] Components registration
1111
- [ ] Compile time macros
1212
- [x] Merge with normal scripts
13+
- [x] Vite plugin
14+
- [x] Webpack plugin
1315

1416
## Sponsors
1517

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
".": {
1010
"require": "./dist/index.js",
1111
"import": "./dist/index.mjs"
12+
},
13+
"./vite-plugin": {
14+
"require": "./dist/vite-plugin.js",
15+
"import": "./dist/vite-plugin.mjs"
16+
},
17+
"./webpack-plugin": {
18+
"require": "./dist/webpack-plugin.js",
19+
"import": "./dist/webpack-plugin.mjs"
1220
}
1321
},
1422
"funding": "https://github.com/sponsors/antfu",
@@ -29,8 +37,7 @@
2937
"scripts": {
3038
"prepublishOnly": "nr build",
3139
"dev": "nr build --watch",
32-
"start": "esno src/index.ts",
33-
"build": "tsup src/index.ts --format cjs,esm --dts --no-splitting",
40+
"build": "tsup src/index.ts src/vite-plugin.ts src/webpack-plugin.ts --format cjs,esm --dts --no-splitting",
3441
"play": "npm -C playground run dev",
3542
"release": "bumpp --commit --push --tag && pnpm publish",
3643
"lint": "eslint \"{src,test}/**/*.ts\"",
@@ -50,7 +57,8 @@
5057
"jest": "^27.0.6",
5158
"ts-jest": "^27.0.4",
5259
"tsup": "^4.13.1",
53-
"typescript": "^4.3.5"
60+
"typescript": "^4.3.5",
61+
"vite": "^2.5.0"
5462
},
5563
"dependencies": {
5664
"@babel/core": "^7.15.0",
@@ -59,6 +67,7 @@
5967
"@babel/traverse": "^7.15.0",
6068
"@vue/shared": "^3.2.4",
6169
"htmlparser2": "^6.1.0",
62-
"magic-string": "^0.25.7"
70+
"magic-string": "^0.25.7",
71+
"unplugin": "^0.0.5"
6372
}
6473
}

playground/vite.config.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import { defineConfig } from 'vite'
22
import { createVuePlugin as Vue2 } from 'vite-plugin-vue2'
33
import Inspect from 'vite-plugin-inspect'
4-
import { transform } from '../src'
4+
import ScriptSetup from '../src/vite-plugin'
55

66
export default defineConfig({
77
plugins: [
88
Vue2(),
99
Inspect(),
10-
{
11-
name: 'vue2-script-setup-transform',
12-
enforce: 'pre',
13-
transform(code, id) {
14-
if (id.endsWith('.vue'))
15-
return transform(code)
16-
},
17-
},
10+
ScriptSetup(),
1811
],
1912
})

0 commit comments

Comments
 (0)