refactor: externalize @nuxt/app

This commit is contained in:
Pooya Parsa 2021-03-28 22:33:19 +02:00
parent 46f771a98b
commit c95d88c6cb
42 changed files with 43 additions and 15 deletions

31
packages/app/package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "@nuxt/app",
"version": "0.0.0",
"repository": "nuxt/framework",
"license": "MIT",
"main": "./dist/index.ts",
"files": [
"dist"
],
"scripts": {
"build": "mkdist",
"stub": "rm -rf dist && ln -s src dist #",
"prepublishOnly": "yarn build"
},
"dependencies": {
"create-require": "^1.1.1",
"defu": "^3.2.2",
"dotenv": "^8.2.0",
"jiti": "^1.6.4",
"rc9": "^1.2.0",
"scule": "^0.1.1",
"std-env": "^2.3.0",
"ufo": "^0.6.10",
"untyped": "^0.2.2"
},
"build": {
"entries": {
"index": {}
}
}
}

View File

@ -4,6 +4,7 @@
"repository": "nuxt/framework",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
@ -26,7 +27,7 @@
},
"build": {
"entries": {
"index": {}
"index": { "format": "cjs" }
}
}
}

View File

@ -14,7 +14,7 @@
},
"build": {
"entries": {
"index": {},
"index": { "format": "cjs" },
"compat": { "format": "cjs" },
"runtime/": {}
},

View File

@ -14,8 +14,7 @@
},
"build": {
"entries": {
"index": {},
"app/": {}
"index": { "format": "cjs" }
},
"dependencies": [
"@vue/compiler-sfc",
@ -39,6 +38,7 @@
]
},
"dependencies": {
"@nuxt/app": "0.0.0",
"@nuxt/friendly-errors-webpack-plugin": "^2.5.0",
"@nuxt/nitro": "^0.1.11",
"@vitejs/plugin-vue": "^1.1.5",

View File

@ -1,3 +0,0 @@
import { resolve } from 'path'
export const APP_DIR = resolve(__dirname, 'app')

View File

@ -1,4 +1,4 @@
import { resolve } from 'path'
import { dirname } from 'path'
import { loadNuxtConfig } from '@nuxt/kit'
import Nuxt from './nuxt'
export interface LoadNuxtOptions {
@ -8,7 +8,7 @@ export async function loadNuxt (opts: LoadNuxtOptions) {
const options = await loadNuxtConfig(opts)
// Temp
options.appDir = resolve(__dirname, '../app')
options.appDir = dirname(require.resolve('@nuxt/app'))
options._majorVersion = 3
const nuxt = new Nuxt(options)

View File

@ -1,4 +1,3 @@
export { loadNuxt } from './core'
export { build } from './builder'
export { main } from './cli'

View File

@ -56,12 +56,12 @@ async function main () {
if (entry.bundle) {
const input = resolve(ctx.rootDir, entry.input)
stubbed.push(entry.output)
const output = resolve(ctx.rootDir, entry.output) + '.ts'
const output = resolve(ctx.rootDir, entry.output) + '.js'
await mkdir(dirname(output)).catch(() => { })
await writeFile(output, entry.format === 'cjs'
? `module.exports = require('jiti')()('${input}')`
: `export * from '${input}'`
)
const cjsStub = `module.exports = require('jiti')()('${input}')`
const esStub = `export * from '${input}'`
await writeFile(output, entry.format === 'cjs' ? cjsStub : esStub)
await writeFile(output.replace('.js', '.d.ts'), esStub)
}
}
consola.success(`Stub done: ${stubbed.join(', ')}`)