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

Commit ad0a9af

Browse files
committed
feat: ships nuxt moudle
1 parent 1b765db commit ad0a9af

13 files changed

+9723
-3330
lines changed

Diff for: .npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

Diff for: README.md

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ export default defineConfig({
3838
})
3939
```
4040

41+
###### Nuxt
42+
43+
```bash
44+
npm i @nuxtjs/composition-api
45+
```
46+
47+
```ts
48+
// nuxt.config.js
49+
export default {
50+
buildModules: [
51+
'@nuxtjs/composition-api/module',
52+
'vue2-script-setup-transform/nuxt',
53+
],
54+
}
55+
```
56+
57+
See [`examples/nuxt`](./examples/nuxt).
58+
4159
###### Webpack
4260

4361
```ts

Diff for: examples/nuxt/components/HelloWorld.vue

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div>
3+
<h3>{{ msg }}, {{ name }}</h3>
4+
<button @click="inc">
5+
Inc
6+
</button>
7+
<div>{{ count }} x 2 = {{ doubled }}</div>
8+
<button @click="dec()" v-html="decText" />
9+
</div>
10+
</template>
11+
12+
<script setup lang="ts">
13+
import { ref, computed, watch } from '@vue/composition-api'
14+
15+
const props = withDefaults(defineProps<{ msg: string; name: string | number }>(), { msg: 'Hello' })
16+
const emit = defineEmits(['update'])
17+
18+
const count = ref(0)
19+
const doubled = computed(() => count.value * 2)
20+
21+
function inc() {
22+
count.value += 1
23+
}
24+
25+
function dec() {
26+
count.value += 1
27+
}
28+
29+
const decText = '<b>Dec</b>'
30+
31+
watch(count, value => emit('update', value))
32+
</script>
33+
34+
<script lang="ts">
35+
export default {
36+
name: 'App'
37+
}
38+
</script>

Diff for: examples/nuxt/nuxt.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
buildModules: [
3+
'@nuxt/typescript-build',
4+
'@nuxtjs/composition-api/module',
5+
'vue2-script-setup-transform/nuxt',
6+
],
7+
}

Diff for: examples/nuxt/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "nuxt-example",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "nuxt",
7+
"build": "nuxt build",
8+
"start": "nuxt start",
9+
"generate": "nuxt generate"
10+
},
11+
"dependencies": {
12+
"core-js": "^3.15.1",
13+
"nuxt": "^2.15.7"
14+
},
15+
"devDependencies": {
16+
"@nuxt/types": "^2.15.8",
17+
"@nuxt/typescript-build": "^2.1.0",
18+
"@nuxtjs/composition-api": "^0.27.0",
19+
"vue2-script-setup-transform": "workspace:*"
20+
}
21+
}

Diff for: examples/nuxt/pages/index.vue

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<hello-world name="Vue 2" @update="onUpdate" />
4+
</div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import HelloWorld from '../components/HelloWorld.vue'
9+
10+
function onUpdate(e: any) {
11+
console.log(e)
12+
}
13+
</script>

Diff for: examples/nuxt/tsconfig.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2018",
4+
"module": "ESNext",
5+
"moduleResolution": "Node",
6+
"lib": [
7+
"ESNext",
8+
"ESNext.AsyncIterable",
9+
"DOM"
10+
],
11+
"esModuleInterop": true,
12+
"allowJs": true,
13+
"sourceMap": true,
14+
"strict": true,
15+
"noEmit": true,
16+
"baseUrl": ".",
17+
"paths": {
18+
"~/*": [
19+
"./*"
20+
],
21+
"@/*": [
22+
"./*"
23+
]
24+
},
25+
"types": [
26+
"@types/node",
27+
"@nuxt/types"
28+
]
29+
},
30+
"exclude": [
31+
"node_modules"
32+
]
33+
}

Diff for: nuxt.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './global'
2+
export * from './dist/nuxt'

Diff for: package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"./webpack-plugin": {
1818
"require": "./dist/webpack-plugin.js",
1919
"import": "./dist/webpack-plugin.mjs"
20+
},
21+
"./nuxt": {
22+
"require": "./dist/nuxt.js",
23+
"import": "./dist/nuxt.mjs"
2024
}
2125
},
2226
"funding": "https://github.com/sponsors/antfu",
@@ -38,7 +42,7 @@
3842
"scripts": {
3943
"prepublishOnly": "nr build",
4044
"dev": "nr build --watch",
41-
"build": "tsup src/index.ts src/vite-plugin.ts src/webpack-plugin.ts --format cjs,esm --dts --no-splitting",
45+
"build": "rimraf dist && tsup src/index.ts src/vite-plugin.ts src/webpack-plugin.ts src/nuxt.ts --format cjs,esm --dts",
4246
"play": "npm -C playground run dev",
4347
"release": "bumpp --commit --push --tag && pnpm publish",
4448
"lint": "eslint \"{src,test}/**/*.ts\"",
@@ -57,6 +61,7 @@
5761
"eslint-plugin-jest": "^24.4.0",
5862
"esno": "^0.9.1",
5963
"jest": "^27.0.6",
64+
"rimraf": "^3.0.2",
6065
"ts-jest": "^27.0.5",
6166
"tsup": "^4.14.0",
6267
"typescript": "^4.3.5",
@@ -71,6 +76,6 @@
7176
"@vue/shared": "^3.2.4",
7277
"htmlparser2": "^6.1.0",
7378
"magic-string": "^0.25.7",
74-
"unplugin": "^0.0.5"
79+
"unplugin": "^0.0.6"
7580
}
7681
}

0 commit comments

Comments
 (0)