mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
feat: prepare for npm publish
This commit is contained in:
parent
acc76ed2df
commit
47c738cd9d
18
packages/nuxt3/src/cli.ts
Executable file
18
packages/nuxt3/src/cli.ts
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
import { resolve } from 'path'
|
||||||
|
import { loadNuxt, build } from '.'
|
||||||
|
|
||||||
|
async function _main () {
|
||||||
|
const rootDir = resolve(process.cwd(), process.argv[2] || '.')
|
||||||
|
const nuxt = await loadNuxt({ for: 'dev', rootDir })
|
||||||
|
const [{ url }] = await nuxt.server.listen(3000)
|
||||||
|
console.log('Listening:', url)
|
||||||
|
await build(nuxt)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function main () {
|
||||||
|
_main()
|
||||||
|
.catch((error) => {
|
||||||
|
require('consola').fatal(error)
|
||||||
|
require('exit')(2)
|
||||||
|
})
|
||||||
|
}
|
@ -2,6 +2,7 @@ import { resolve, join } from 'path'
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
|
||||||
import { Nuxt } from 'src/core'
|
import { Nuxt } from 'src/core'
|
||||||
|
import jiti from 'jiti'
|
||||||
import {
|
import {
|
||||||
startsWithRootAlias,
|
startsWithRootAlias,
|
||||||
startsWithSrcAlias,
|
startsWithSrcAlias,
|
||||||
@ -37,10 +38,8 @@ export default class Resolver {
|
|||||||
this.resolveModule = this.resolveModule.bind(this)
|
this.resolveModule = this.resolveModule.bind(this)
|
||||||
this.requireModule = this.requireModule.bind(this)
|
this.requireModule = this.requireModule.bind(this)
|
||||||
|
|
||||||
const { createRequire } = this.options
|
this._require = jiti(__filename)
|
||||||
this._require = createRequire ? createRequire(module) : module.require
|
this._resolve = this._require.resolve
|
||||||
|
|
||||||
this._resolve = require.resolve
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveModule (path: string) {
|
resolveModule (path: string) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
export * from './core'
|
|
||||||
|
|
||||||
export const APP_DIR = resolve(__dirname, 'app')
|
export const APP_DIR = resolve(__dirname, 'app')
|
||||||
|
|
||||||
export const getBuilder = () => import('./builder')
|
export { loadNuxt } from './core'
|
||||||
|
export { build } from './builder'
|
||||||
|
export { main } from './cli'
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
export * from './context'
|
export * from './context'
|
||||||
export * from './lang'
|
export * from './lang'
|
||||||
export * from './locking'
|
// export * from './locking'
|
||||||
export * from './resolve'
|
export * from './resolve'
|
||||||
export * from './route'
|
export * from './route'
|
||||||
export * from './serialize'
|
// export * from './serialize'
|
||||||
export * from './task'
|
export * from './task'
|
||||||
export * from './timer'
|
// export * from './timer'
|
||||||
export * from './cjs'
|
export * from './cjs'
|
||||||
export * from './modern'
|
// export * from './modern'
|
||||||
export * from './constants'
|
export * from './constants'
|
||||||
|
@ -6,7 +6,7 @@ import webpackDevMiddleware from 'webpack-dev-middleware'
|
|||||||
import webpackHotMiddleware from 'webpack-hot-middleware'
|
import webpackHotMiddleware from 'webpack-hot-middleware'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import { Nuxt } from 'src/core'
|
import { Nuxt } from 'src/core'
|
||||||
import { TARGETS, parallel, sequence, wrapArray, isModernRequest } from 'src/utils'
|
import { TARGETS, parallel, sequence, wrapArray } from 'src/utils'
|
||||||
import { createMFS } from './utils/mfs'
|
import { createMFS } from './utils/mfs'
|
||||||
import { client, server } from './configs'
|
import { client, server } from './configs'
|
||||||
import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config'
|
import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config'
|
||||||
@ -201,14 +201,12 @@ export class WebpackBundler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async middleware (req, res, next) {
|
async middleware (req, res, next) {
|
||||||
const name = isModernRequest(req, this.nuxt.options.modern) ? 'modern' : 'client'
|
if (this.devMiddleware && this.devMiddleware.client) {
|
||||||
|
await this.devMiddleware.client(req, res)
|
||||||
if (this.devMiddleware && this.devMiddleware[name]) {
|
|
||||||
await this.devMiddleware[name](req, res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hotMiddleware && this.hotMiddleware[name]) {
|
if (this.hotMiddleware && this.hotMiddleware.client) {
|
||||||
await this.hotMiddleware[name](req, res)
|
await this.hotMiddleware.client(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
next()
|
next()
|
||||||
|
@ -3,7 +3,7 @@ import TimeFixPlugin from 'time-fix-plugin'
|
|||||||
import WebpackBar from 'webpackbar'
|
import WebpackBar from 'webpackbar'
|
||||||
import stdEnv from 'std-env'
|
import stdEnv from 'std-env'
|
||||||
import { DefinePlugin, Configuration } from 'webpack'
|
import { DefinePlugin, Configuration } from 'webpack'
|
||||||
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
// import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
||||||
import { isUrl, urlJoin, TARGETS } from 'src/utils'
|
import { isUrl, urlJoin, TARGETS } from 'src/utils'
|
||||||
import escapeRegExp from 'lodash/escapeRegExp'
|
import escapeRegExp from 'lodash/escapeRegExp'
|
||||||
import WarningIgnorePlugin from '../plugins/warning-ignore'
|
import WarningIgnorePlugin from '../plugins/warning-ignore'
|
||||||
@ -23,7 +23,7 @@ function baseConfig (ctx: WebpackConfigContext) {
|
|||||||
|
|
||||||
ctx.config = {
|
ctx.config = {
|
||||||
name: ctx.name,
|
name: ctx.name,
|
||||||
entry: { app: [resolve(options.buildDir, `entry.${ctx.name}.ts`)] },
|
entry: { app: [resolve(options.buildDir, `entry.${ctx.name}`)] },
|
||||||
module: { rules: [] },
|
module: { rules: [] },
|
||||||
plugins: [],
|
plugins: [],
|
||||||
externals: [],
|
externals: [],
|
||||||
@ -57,18 +57,18 @@ function basePlugins (ctx: WebpackConfigContext) {
|
|||||||
config.plugins.push(new DefinePlugin(getEnv(ctx)))
|
config.plugins.push(new DefinePlugin(getEnv(ctx)))
|
||||||
|
|
||||||
// Friendly errors
|
// Friendly errors
|
||||||
if (
|
// if (
|
||||||
ctx.isServer ||
|
// ctx.isServer ||
|
||||||
(ctx.isDev && !options.build.quiet && options.build.friendlyErrors)
|
// (ctx.isDev && !options.build.quiet && options.build.friendlyErrors)
|
||||||
) {
|
// ) {
|
||||||
ctx.config.plugins.push(
|
// ctx.config.plugins.push(
|
||||||
new FriendlyErrorsWebpackPlugin({
|
// new FriendlyErrorsWebpackPlugin({
|
||||||
clearConsole: false,
|
// clearConsole: false,
|
||||||
reporter: 'consola',
|
// reporter: 'consola',
|
||||||
logLevel: 'WARNING'
|
// logLevel: 'WARNING'
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Webpackbar
|
// Webpackbar
|
||||||
const colors = {
|
const colors = {
|
||||||
@ -111,12 +111,11 @@ function basePlugins (ctx: WebpackConfigContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function baseAlias (ctx: WebpackConfigContext) {
|
function baseAlias (ctx: WebpackConfigContext) {
|
||||||
const { options, isServer } = ctx
|
const { options } = ctx
|
||||||
|
|
||||||
ctx.alias = {
|
ctx.alias = {
|
||||||
'nuxt/app': options.appDir,
|
'nuxt/app': options.appDir,
|
||||||
'~build': options.buildDir,
|
'~build': options.buildDir,
|
||||||
'vue-meta': require.resolve(`vue-meta${isServer ? '' : '/dist/vue-meta.esm.browser.js'}`),
|
|
||||||
...options.alias,
|
...options.alias,
|
||||||
...ctx.alias
|
...ctx.alias
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user