feat: prepare for npm publish

This commit is contained in:
Pooya Parsa 2021-01-20 15:43:43 +01:00
parent acc76ed2df
commit 47c738cd9d
6 changed files with 48 additions and 33 deletions

18
packages/nuxt3/src/cli.ts Executable file
View 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)
})
}

View File

@ -2,6 +2,7 @@ import { resolve, join } from 'path'
import fs from 'fs-extra'
import { Nuxt } from 'src/core'
import jiti from 'jiti'
import {
startsWithRootAlias,
startsWithSrcAlias,
@ -37,10 +38,8 @@ export default class Resolver {
this.resolveModule = this.resolveModule.bind(this)
this.requireModule = this.requireModule.bind(this)
const { createRequire } = this.options
this._require = createRequire ? createRequire(module) : module.require
this._resolve = require.resolve
this._require = jiti(__filename)
this._resolve = this._require.resolve
}
resolveModule (path: string) {

View File

@ -1,6 +1,7 @@
import { resolve } from 'path'
export * from './core'
export const APP_DIR = resolve(__dirname, 'app')
export const getBuilder = () => import('./builder')
export { loadNuxt } from './core'
export { build } from './builder'
export { main } from './cli'

View File

@ -1,11 +1,11 @@
export * from './context'
export * from './lang'
export * from './locking'
// export * from './locking'
export * from './resolve'
export * from './route'
export * from './serialize'
// export * from './serialize'
export * from './task'
export * from './timer'
// export * from './timer'
export * from './cjs'
export * from './modern'
// export * from './modern'
export * from './constants'

View File

@ -6,7 +6,7 @@ import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import consola from 'consola'
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 { client, server } from './configs'
import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config'
@ -201,14 +201,12 @@ export class WebpackBundler {
}
async middleware (req, res, next) {
const name = isModernRequest(req, this.nuxt.options.modern) ? 'modern' : 'client'
if (this.devMiddleware && this.devMiddleware[name]) {
await this.devMiddleware[name](req, res)
if (this.devMiddleware && this.devMiddleware.client) {
await this.devMiddleware.client(req, res)
}
if (this.hotMiddleware && this.hotMiddleware[name]) {
await this.hotMiddleware[name](req, res)
if (this.hotMiddleware && this.hotMiddleware.client) {
await this.hotMiddleware.client(req, res)
}
next()

View File

@ -3,7 +3,7 @@ import TimeFixPlugin from 'time-fix-plugin'
import WebpackBar from 'webpackbar'
import stdEnv from 'std-env'
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 escapeRegExp from 'lodash/escapeRegExp'
import WarningIgnorePlugin from '../plugins/warning-ignore'
@ -23,7 +23,7 @@ function baseConfig (ctx: WebpackConfigContext) {
ctx.config = {
name: ctx.name,
entry: { app: [resolve(options.buildDir, `entry.${ctx.name}.ts`)] },
entry: { app: [resolve(options.buildDir, `entry.${ctx.name}`)] },
module: { rules: [] },
plugins: [],
externals: [],
@ -57,18 +57,18 @@ function basePlugins (ctx: WebpackConfigContext) {
config.plugins.push(new DefinePlugin(getEnv(ctx)))
// Friendly errors
if (
ctx.isServer ||
(ctx.isDev && !options.build.quiet && options.build.friendlyErrors)
) {
ctx.config.plugins.push(
new FriendlyErrorsWebpackPlugin({
clearConsole: false,
reporter: 'consola',
logLevel: 'WARNING'
})
)
}
// if (
// ctx.isServer ||
// (ctx.isDev && !options.build.quiet && options.build.friendlyErrors)
// ) {
// ctx.config.plugins.push(
// new FriendlyErrorsWebpackPlugin({
// clearConsole: false,
// reporter: 'consola',
// logLevel: 'WARNING'
// })
// )
// }
// Webpackbar
const colors = {
@ -111,12 +111,11 @@ function basePlugins (ctx: WebpackConfigContext) {
}
function baseAlias (ctx: WebpackConfigContext) {
const { options, isServer } = ctx
const { options } = ctx
ctx.alias = {
'nuxt/app': options.appDir,
'~build': options.buildDir,
'vue-meta': require.resolve(`vue-meta${isServer ? '' : '/dist/vue-meta.esm.browser.js'}`),
...options.alias,
...ctx.alias
}