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

Commit

Permalink
refactor: use runtime/ directory for library code (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored May 12, 2021
1 parent 86ed34e commit 1d374fa
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
"sideEffects": true,
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"import": "./dist/runtime/index.mjs",
"require": "./dist/runtime/index.js"
},
"./module": "./dist/module.js",
"./package.json": "./package.json",
"./dist/babel-plugin": "./dist/babel-plugin.js",
"./dist/runtime/globals": "./dist/runtime/globals.js",
"./dist/runtime/register": "./dist/runtime/register.js",
"./dist/runtime/templates/*": "./dist/runtime/templates/*"
"./dist/runtime/*": "./dist/runtime/*"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"main": "./dist/runtime/index.js",
"module": "./dist/runtime/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './runtime/composables'
/* dummy entry for types field */
export * from './runtime'
11 changes: 2 additions & 9 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@ const compositionApiModule: Module<never> = function compositionApiModule() {

addGlobalsFile.call(this)

// Add library alias for benefit of vite

nuxtOptions.alias['~composition-api'] = resolve(__dirname, 'index.mjs')

// Force transpilation of this library (to enable resolution of globals file)

const runtimeDir = resolve(__dirname, 'runtime')
nuxtOptions.build.transpile = nuxtOptions.build.transpile || []
nuxtOptions.build.transpile.push(
'@nuxtjs/composition-api',
'~composition-api',
__dirname
)
nuxtOptions.build.transpile.push('@nuxtjs/composition-api', runtimeDir)

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

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@nuxtjs/composition-api/dist/runtime/register'
import '../register'

export { useAsync } from './async'
export { defineComponent } from './component'
Expand Down
1 change: 1 addition & 0 deletions src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './composables'
4 changes: 0 additions & 4 deletions src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export function compositionApiPlugin(): Plugin & { enforce: 'pre' } {
name: 'nuxt:composition-api',
enforce: 'pre',
transform(code: string, filename: string) {
code = code.replace(
/@nuxtjs[\\/]composition-api(?![\\/])/g,
'~composition-api'
)
const keyedFunctions =
/(useStatic|shallowSsrRef|ssrPromise|ssrRef|reqSsrRef|useAsync)/
if (!keyedFunctions.test(code)) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default <NuxtConfig>{
),
'@nuxtjs/composition-api': join(
rootDir,
inDevelopment ? 'src/index.ts' : 'dist/index.js'
inDevelopment ? 'src/runtime/index.ts' : 'dist/runtime/index.js'
),
},
target: isGenerated ? 'static' : 'server',
Expand Down

0 comments on commit 1d374fa

Please sign in to comment.