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

Commit 1d374fa

Browse files
authored
refactor: use runtime/ directory for library code (#480)
1 parent 86ed34e commit 1d374fa

File tree

7 files changed

+12
-23
lines changed

7 files changed

+12
-23
lines changed

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
"sideEffects": true,
2121
"exports": {
2222
".": {
23-
"import": "./dist/index.mjs",
24-
"require": "./dist/index.js"
23+
"import": "./dist/runtime/index.mjs",
24+
"require": "./dist/runtime/index.js"
2525
},
2626
"./module": "./dist/module.js",
2727
"./package.json": "./package.json",
2828
"./dist/babel-plugin": "./dist/babel-plugin.js",
29-
"./dist/runtime/globals": "./dist/runtime/globals.js",
30-
"./dist/runtime/register": "./dist/runtime/register.js",
31-
"./dist/runtime/templates/*": "./dist/runtime/templates/*"
29+
"./dist/runtime/*": "./dist/runtime/*"
3230
},
33-
"main": "./dist/index.js",
34-
"module": "./dist/index.mjs",
31+
"main": "./dist/runtime/index.js",
32+
"module": "./dist/runtime/index.mjs",
3533
"types": "./dist/index.d.ts",
3634
"files": [
3735
"dist",

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from './runtime/composables'
1+
/* dummy entry for types field */
2+
export * from './runtime'

src/module.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@ const compositionApiModule: Module<never> = function compositionApiModule() {
1414

1515
addGlobalsFile.call(this)
1616

17-
// Add library alias for benefit of vite
18-
19-
nuxtOptions.alias['~composition-api'] = resolve(__dirname, 'index.mjs')
20-
2117
// Force transpilation of this library (to enable resolution of globals file)
2218

19+
const runtimeDir = resolve(__dirname, 'runtime')
2320
nuxtOptions.build.transpile = nuxtOptions.build.transpile || []
24-
nuxtOptions.build.transpile.push(
25-
'@nuxtjs/composition-api',
26-
'~composition-api',
27-
__dirname
28-
)
21+
nuxtOptions.build.transpile.push('@nuxtjs/composition-api', runtimeDir)
2922

3023
// Define @vue/composition-api resolution to prevent using different versions of @vue/composition-api
3124

src/runtime/composables/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '@nuxtjs/composition-api/dist/runtime/register'
1+
import '../register'
22

33
export { useAsync } from './async'
44
export { defineComponent } from './component'

src/runtime/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './composables'

src/vite-plugin.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export function compositionApiPlugin(): Plugin & { enforce: 'pre' } {
1717
name: 'nuxt:composition-api',
1818
enforce: 'pre',
1919
transform(code: string, filename: string) {
20-
code = code.replace(
21-
/@nuxtjs[\\/]composition-api(?![\\/])/g,
22-
'~composition-api'
23-
)
2420
const keyedFunctions =
2521
/(useStatic|shallowSsrRef|ssrPromise|ssrRef|reqSsrRef|useAsync)/
2622
if (!keyedFunctions.test(code)) {

test/fixture/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default <NuxtConfig>{
2727
),
2828
'@nuxtjs/composition-api': join(
2929
rootDir,
30-
inDevelopment ? 'src/index.ts' : 'dist/index.js'
30+
inDevelopment ? 'src/runtime/index.ts' : 'dist/runtime/index.js'
3131
),
3232
},
3333
target: isGenerated ? 'static' : 'server',

0 commit comments

Comments
 (0)