Skip to content

Commit

Permalink
chore: migrate to unenv and mkbuild 0.2 (nuxt#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Apr 21, 2021
1 parent 4c0dba2 commit de9dffb
Show file tree
Hide file tree
Showing 37 changed files with 117 additions and 102 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"lerna": "^4.0.0",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}
6 changes: 3 additions & 3 deletions packages/app/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: true,
entries: [
{ input: 'src/', name: 'app' }
Expand All @@ -11,4 +11,4 @@ export default <BuildConfig>{
'vue-router',
'vuex5'
]
}
})
2 changes: 1 addition & 1 deletion packages/app/meta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { resolve } = require('path')

module.exports = {
appDir: resolve(__dirname, 'dist/app')
appDir: resolve(__dirname, 'dist')
}
14 changes: 9 additions & 5 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
"version": "0.3.1",
"repository": "nuxt/framework",
"license": "MIT",
"main": "./dist/app/index.js",
"module": "./dist/app/index.js",
"exports": {
".": "./dist",
"./meta": "./meta.js"
},
"main": "./dist",
"module": "./dist",
"types": "./types/index.d.ts",
"files": [
"dist",
Expand All @@ -14,15 +18,15 @@
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.13"
},
"dependencies": {
"@vueuse/head": "^0.5.1",
"hookable": "^4.4.1",
"ohmyfetch": "^0.2.0",
"vue": "^3.0.11",
"vue-router": "^4.0.6",
"vuex5": "^0.5.0-testing.3"
},
"devDependencies": {
"unbuild": "^0.2.2"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/app/src/_templates/views/app.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<body {{ BODY_ATTRS }}>
<div id="__nuxt">{{ APP }}</div>
<% if (nuxtOptions.vite && nuxtOptions.dev) { %><script type="module" src="/@vite/client"></script>
<script type="module" src="/entry.client.js"></script><% } %>
<script type="module" src="/entry.client.mjs"></script><% } %>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/app/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import './shims'

export * from '../dist/app'
export * from '../dist'
2 changes: 1 addition & 1 deletion packages/app/types/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare module '*.vue' {
}

declare module 'vue' {
import type { Nuxt } from '../dist/app'
import type { Nuxt } from '../dist'

interface App {
$nuxt: Nuxt
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
inlineDependencies: true,
entries: [
Expand All @@ -10,4 +10,4 @@ export default <BuildConfig>{
'@nuxt/kit',
'fsevents'
]
}
})
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"flat": "^5.0.2",
"listhen": "^0.2.4",
"mri": "^1.1.6",
"unbuild": "^0.1.13",
"unbuild": "^0.2.2",
"v8-compile-cache": "^2.3.0"
}
}
1 change: 1 addition & 0 deletions packages/kit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schema
7 changes: 4 additions & 3 deletions packages/kit/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: true,
entries: [
{
input: 'src/config/schema/index',
outDir: 'schema',
name: 'config',
builder: 'untyped',
defaults: {
Expand All @@ -18,4 +19,4 @@ export default <BuildConfig>{
'nuxt',
'nuxt3'
]
}
})
5 changes: 3 additions & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
"dist",
"schema"
],
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
},
"dependencies": {
"consola": "^2.15.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigSchema } from '../../.gen/config/config'
import { ConfigSchema } from '../../schema/config'
import { ModuleInstallOptions } from './module'
import { NuxtHooks } from './hooks'

Expand Down
9 changes: 5 additions & 4 deletions packages/nitro/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: true,
entries: [
'src/index',
'src/compat',
{ input: 'src/runtime/', format: 'esm' }
{ input: 'src/runtime/', outDir: 'dist/runtime', format: 'esm' },
{ input: 'src/runtime/', outDir: 'dist/runtime', format: 'cjs', declaration: false }
],
dependencies: [
'@cloudflare/kv-asset-handler',
Expand All @@ -20,4 +21,4 @@ export default <BuildConfig>{
'@vue/server-renderer',
'vue'
]
}
})
4 changes: 2 additions & 2 deletions packages/nitro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@netlify/functions": "^0.7.0",
"@nuxt/devalue": "^1.2.5",
"@nuxt/kit": "^0.5.0",
"@nuxt/un": "^0.1.1",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-inject": "^4.0.2",
Expand Down Expand Up @@ -62,6 +61,7 @@
"std-env": "^2.3.0",
"table": "^6.3.0",
"ufo": "^0.6.11",
"unenv": "^0.2.1",
"unstorage": "^0.1.5",
"upath": "^2.0.1",
"vue": "3.0.11",
Expand All @@ -74,6 +74,6 @@
"@types/http-proxy": "^1.17.5",
"@types/node-fetch": "^2.5.10",
"@types/serve-static": "^1.13.9",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}
2 changes: 1 addition & 1 deletion packages/nitro/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve, dirname } from 'upath'
import defu from 'defu'
import type { NuxtOptions } from '@nuxt/kit'
import Hookable, { configHooksT } from 'hookable'
import type { Preset } from '@nuxt/un'
import type { Preset } from 'unenv'
import { tryImport, resolvePath, detectTarget, extendPreset } from './utils'
import * as PRESETS from './presets'
import type { NodeExternalsOptions } from './rollup/plugins/externals'
Expand Down
36 changes: 18 additions & 18 deletions packages/nitro/src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import replace from '@rollup/plugin-replace'
import virtual from '@rollup/plugin-virtual'
import inject from '@rollup/plugin-inject'
import analyze from 'rollup-plugin-analyzer'
import type { Preset } from '@nuxt/un'
import * as un from '@nuxt/un'
import type { Preset } from 'unenv'
import * as unenv from 'unenv'

import { NitroContext } from '../context'
import { resolvePath, MODULE_DIR } from '../utils'
Expand All @@ -32,31 +32,31 @@ export type RollupConfig = InputOptions & { output: OutputOptions }
export const getRollupConfig = (nitroContext: NitroContext) => {
const extensions: string[] = ['.ts', '.mjs', '.js', '.json', '.node']

const nodePreset = nitroContext.node === false ? un.nodeless : un.node
const nodePreset = nitroContext.node === false ? unenv.nodeless : unenv.node

const builtinPreset: Preset = {
alias: {
// General
debug: 'un/npm/debug',
depd: 'un/npm/depd',
consola: 'un/npm/consola',
debug: 'unenv/runtime/npm/debug',
depd: 'unenv/runtime/npm/depd',
consola: 'unenv/runtime/npm/consola',
// Vue 2
encoding: 'un/mock/proxy',
he: 'un/mock/proxy',
resolve: 'un/mock/proxy',
'source-map': 'un/mock/proxy',
'lodash.template': 'un/mock/proxy',
'serialize-javascript': 'un/mock/proxy',
encoding: 'unenv/runtime/mock/proxy',
he: 'unenv/runtime/mock/proxy',
resolve: 'unenv/runtime/mock/proxy',
'source-map': 'unenv/runtime/mock/proxy',
'lodash.template': 'unenv/runtime/mock/proxy',
'serialize-javascript': 'unenv/runtime/mock/proxy',
// Vue 3
'estree-walker': 'un/mock/proxy',
'@babel/parser': 'un/mock/proxy',
'@vue/compiler-core': 'un/mock/proxy',
'@vue/compiler-dom': 'un/mock/proxy',
'@vue/compiler-ssr': 'un/mock/proxy'
'estree-walker': 'unenv/runtime/mock/proxy',
'@babel/parser': 'unenv/runtime/mock/proxy',
'@vue/compiler-core': 'unenv/runtime/mock/proxy',
'@vue/compiler-dom': 'unenv/runtime/mock/proxy',
'@vue/compiler-ssr': 'unenv/runtime/mock/proxy'
}
}

const env = un.env(nodePreset, builtinPreset, nitroContext.env)
const env = unenv.env(nodePreset, builtinPreset, nitroContext.env)

delete env.alias['node-fetch'] // FIX ME

Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/rollup/plugins/automock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function autoMock () {
if (src && !src.startsWith('.') && !src.includes('?') && !src.includes('.js')) {
consola.warn('Auto mock external ', src)
return {
id: require.resolve('@nuxt/un/runtime/mock/proxy')
id: require.resolve('unenv/runtime/mock/proxy')
}
}
return null
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../app/config'
import { createApp, useBase } from 'h3'
import { createFetch } from 'ohmyfetch'
import destr from 'destr'
import { createCall, createFetch as createLocalFetch } from '@nuxt/un/runtime/fetch'
import { createCall, createFetch as createLocalFetch } from 'unenv/runtime/fetch'
import { timingMiddleware } from './timing'
import { handleError } from './error'
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt3/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
entries: [
'src/index'
Expand All @@ -11,4 +11,4 @@ export default <BuildConfig>{
'@nuxt/webpack-builder',
'nuxt-cli'
]
}
})
2 changes: 1 addition & 1 deletion packages/nuxt3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"@types/fs-extra": "^9.0.11",
"@types/hash-sum": "^1.0.0",
"@types/lodash": "^4.14.168",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}
2 changes: 1 addition & 1 deletion packages/nuxt3/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function compileTemplates (templates: NuxtTemplate[], destDir: string) {
export async function scanTemplates (dir: string, data?: Record<string, any>) {
const templateFiles = (await globby(join(dir, '/**')))

return templateFiles.map(src => ({
return templateFiles.filter(src => !src.endsWith('.d.ts')).map(src => ({
src,
path: relative(dir, src),
data
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
entries: [
'src/index'
Expand All @@ -10,4 +10,4 @@ export default <BuildConfig>{
'@vue/compiler-sfc',
'vue'
]
}
})
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
},
"dependencies": {
"@nuxt/kit": "^0.5.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function buildClient (ctx: ViteBuildContext) {
outDir: 'dist/client',
assetsDir: '.',
rollupOptions: {
input: resolve(ctx.nuxt.options.buildDir, './entry.client.js')
input: resolve(ctx.nuxt.options.buildDir, './entry.client')
}
},
server: {
Expand Down Expand Up @@ -106,7 +106,7 @@ async function buildServer (ctx: ViteBuildContext) {
outDir: 'dist/server',
ssr: true,
rollupOptions: {
input: resolve(ctx.nuxt.options.buildDir, './entry.server.js'),
input: resolve(ctx.nuxt.options.buildDir, './entry.server'),
onwarn (warning, rollupWarn) {
if (!['UNUSED_EXTERNAL_IMPORT'].includes(warning.code)) {
rollupWarn(warning)
Expand All @@ -119,7 +119,7 @@ async function buildServer (ctx: ViteBuildContext) {
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')
await mkdirp(serverDist)
await writeFile(resolve(serverDist, 'client.manifest.json'), 'false')
await writeFile(resolve(serverDist, 'server.js'), 'const entry = require("./entry.server.js"); module.exports = entry.default || entry;')
await writeFile(resolve(serverDist, 'server.js'), 'const entry = require("./entry.server"); module.exports = entry.default || entry;')

await vite.build(serverConfig)

Expand Down
6 changes: 3 additions & 3 deletions packages/webpack/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'

export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
entries: [
'src/index'
Expand All @@ -22,4 +22,4 @@ export default <BuildConfig>{
'@babel/core',
'vue'
]
}
})
2 changes: 1 addition & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"@types/webpack-bundle-analyzer": "^4.4.0",
"@types/webpack-dev-middleware": "^4.1.2",
"@types/webpack-hot-middleware": "^2.25.4",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}
Loading

0 comments on commit de9dffb

Please sign in to comment.