feat: migrate nuxt into monorepo (#4051)

Co-authored-by: Clark Du <clark.duxin@gmail.com>
Co-authored-by: Pooya Parsa <pooya@pi0.ir>
This commit is contained in:
Pooya Parsa 2018-10-18 00:58:25 +03:30
parent e115890a94
commit 9c1e0d1743
140 changed files with 4853 additions and 1500 deletions

View File

@ -1,14 +0,0 @@
{
"env": {
"test": {
"presets": [
["@babel/env", {
"targets": {
"node": "current"
}
}]
],
"plugins": ["dynamic-import-node"]
}
}
}

View File

@ -1,11 +1,16 @@
version: 2
defaults: &defaults
working_directory: ~/project/nuxt
working_directory: ~/project
docker:
- image: banian/node-headless-chrome
environment:
- NODE_ENV: test
jobs:
# --------------------------------------------------------------------------
# Phase 1: Setup
# --------------------------------------------------------------------------
setup:
<<: *defaults
steps:
@ -19,23 +24,36 @@ jobs:
# Install dependencies
- run:
name: Install Dependencies
command: NODE_ENV=dev yarn
command: yarn --frozen-lockfile --non-interactive
# Keep cache
# Link
- run:
name: Link
command: yarn lerna link
# Save cache
- save_cache:
key: yarn-{{ checksum "yarn.lock" }}
paths:
- "node_modules"
- node_modules
- distributions/*/node_modules
- packages/*/node_modules
# Persist files
# Persist workspace
- persist_to_workspace:
root: ~/project
paths:
- nuxt
- node_modules
- distributions/*/node_modules
- packages/*/node_modules
# --------------------------------------------------------------------------
# Phase 2: Lint + Audit + Build Nuxt and fixtures
# --------------------------------------------------------------------------
lint:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
@ -45,6 +63,7 @@ jobs:
audit:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
@ -54,44 +73,52 @@ jobs:
build:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: Build Nuxt
command: yarn build
- run:
name: Build Fixtures
command: yarn build && yarn test:fixtures -w=4 --coverage && yarn coverage
- persist_to_workspace:
root: ~/project
paths:
- nuxt/test/fixtures
- nuxt/dist
environment:
- NODE_ENV: "test"
- test/fixtures # TODO
- distributions/**/dist
- packages/**/dist
# --------------------------------------------------------------------------
# Phase 3: Unit and E2E tests
# --------------------------------------------------------------------------
test-unit:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: Unit Test
name: Unit Tests
command: yarn test:unit -w=4 --coverage && yarn coverage
environment:
- NODE_ENV: "test"
test-e2e:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: E2E Test
name: E2E Tests
command: yarn test:e2e && yarn coverage
environment:
- NODE_ENV: "test"
# --------------------------------------------------------------------------
# Phase 4: Release (dev branch only)
# --------------------------------------------------------------------------
release:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
@ -99,19 +126,14 @@ jobs:
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
echo "//registry.yarnpkg.com/:_authToken=$NPM_TOKEN" >> ~/.npmrc
BUILD_SUFFIX=edge yarn build
npm publish
for p in packages/*; do
if [ -f "$p/package.json" ]; then
cd $p
npm publish
cd -
fi
done
yarn lerna version
PACKAGE_SUFFIX=edge yarn build
yarn lerna publish
# Workflow definition
workflows:
version: 2
setup-and-parallel-test:
setup-and-test:
jobs:
- setup

View File

@ -5,3 +5,4 @@ dist
.nuxt
examples/coffeescript/pages/index.vue
!examples/storybook/.storybook
coverage

23
.gitignore vendored
View File

@ -1,28 +1,33 @@
# Dependencies
node_modules
examples/**/*/yarn.lock
jspm_packages
# Only keep yarn.lock in the root
package-lock.json
**/yarn.lock
# Logs
*.log
npm-debug.log*
yarn-error.log*
# Packages
packages/*/LICENSE
# Distributions
distributions/*/LICENSE
# Other
.nuxt*
.cache
# Dist folder
# Dist folders
dist
# Dist example generation
examples/**/dist
# Coverage support
# Coverage reports
coverage
*.lcov
.nyc_output
# VSCode
.vscode
# Intellij idea
@ -30,7 +35,7 @@ coverage
.idea
# OSX
*.DS_Store
.DS_Store
.AppleDouble
.LSOverride

View File

@ -1,9 +1,6 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "Current"
# environment:
# matrix:
# - nodejs_version: "Current"
cache:
- 'node_modules -> yarn.lock'
@ -17,8 +14,12 @@ shallow_clone: true
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
# Install modules
- yarn install
# Link dependencies
- yarn lerna link
# Build packages
- yarn build
# Post-install test scripts.
test_script:

15
babel.config.js Normal file
View File

@ -0,0 +1,15 @@
module.exports = function (api) {
if (api.env('test')) {
return {
presets: [
['@babel/env', {
targets: {
node: 'current'
}
}]
],
plugins: ['dynamic-import-node']
}
}
return {}
}

View File

@ -1,88 +0,0 @@
#!/usr/bin/env node
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const parseArgs = require('minimist')
const consola = require('consola')
const { Nuxt, Builder, Generator } = require('..')
const { loadNuxtConfig } = require('./common/utils')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
c: 'config-file',
a: 'analyze',
s: 'spa',
u: 'universal',
q: 'quiet'
},
boolean: ['h', 'a', 's', 'u', 'q'],
string: ['c'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.help) {
process.stderr.write(`
Description
Compiles the application for production deployment
Usage
$ nuxt build <dir>
Options
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
--spa, -s Launch in SPA mode
--universal, -u Launch in Universal mode (default)
--no-generate Don't generate static version for SPA mode (useful for nuxt start)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--quiet, -q Disable output except for errors
--help, -h Displays this message
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
// Create production build when calling `nuxt build`
options.dev = false
// Analyze option
options.build = options.build || {}
if (argv.analyze && typeof options.build.analyze !== 'object') {
options.build.analyze = true
}
// Silence output when using --quiet
if (argv.quiet) {
options.build.quiet = !!argv.quiet
}
const nuxt = new Nuxt(options)
const builder = new Builder(nuxt)
// Setup hooks
nuxt.hook('error', err => consola.fatal(err))
// Close function
const close = () => {
// In analyze mode wait for plugin
// emitting assets and opening browser
if (options.build.analyze === true || typeof options.build.analyze === 'object') {
return
}
process.exit(0)
}
if (options.mode !== 'spa' || argv.generate === false) {
// Build only
builder
.build()
.then(close)
.catch(err => consola.fatal(err))
} else {
// Build + Generate for static deployment
new Generator(nuxt, builder)
.generate({ build: true })
.then(close)
.catch(err => consola.fatal(err))
}

View File

@ -1,100 +0,0 @@
#!/usr/bin/env node
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const parseArgs = require('minimist')
const consola = require('consola')
const { version } = require('../package.json')
const { Nuxt, Builder } = require('..')
const { loadNuxtConfig } = require('./common/utils')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
H: 'hostname',
p: 'port',
c: 'config-file',
s: 'spa',
u: 'universal',
v: 'version'
},
boolean: ['h', 's', 'u', 'v'],
string: ['H', 'c'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.version) {
process.stderr.write(version + '\n')
process.exit(0)
}
if (argv.hostname === '') {
consola.fatal('Provided hostname argument has no value')
}
if (argv.help) {
process.stderr.write(`
Description
Starts the application in development mode (hot-code reloading, error
reporting, etc)
Usage
$ nuxt dev <dir> -p <port number> -H <hostname>
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
`)
process.exit(0)
}
const config = () => {
// Force development mode for add hot reloading and watching changes
return Object.assign(loadNuxtConfig(argv), { dev: true })
}
const errorHandler = (err, instance) => {
instance && instance.builder.watchServer()
consola.error(err)
}
// Start dev
(function startDev(oldInstance) {
let nuxt, builder
try {
nuxt = new Nuxt(config())
builder = new Builder(nuxt)
nuxt.hook('watch:fileChanged', (builder, fname) => {
consola.debug(`[${fname}] changed, Rebuilding the app...`)
startDev({ nuxt: builder.nuxt, builder })
})
} catch (err) {
return errorHandler(err, oldInstance)
}
return (
Promise.resolve()
.then(() => oldInstance && oldInstance.nuxt.clearHook('watch:fileChanged'))
.then(() => oldInstance && oldInstance.builder.unwatch())
// Start build
.then(() => builder.build())
// Close old nuxt no mater if build successfully
.catch((err) => {
oldInstance && oldInstance.nuxt.close()
// Jump to eventHandler
throw err
})
.then(() => oldInstance && oldInstance.nuxt.close())
// Start listening
.then(() => nuxt.listen())
// Show ready message first time, others will be shown through WebpackBar
.then(() => !oldInstance && nuxt.showReady(false))
.then(() => builder.watchServer())
// Handle errors
.catch(err => errorHandler(err, { builder, nuxt }))
)
})()

View File

@ -1,58 +0,0 @@
#!/usr/bin/env node
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const parseArgs = require('minimist')
const consola = require('consola')
const { Nuxt, Builder, Generator } = require('..')
const { loadNuxtConfig } = require('./common/utils')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
c: 'config-file',
s: 'spa',
u: 'universal'
},
boolean: ['h', 's', 'u', 'build'],
string: ['c'],
default: {
c: 'nuxt.config.js',
build: true
}
})
if (argv.help) {
process.stderr.write(`
Description
Generate a static web application (server-rendered)
Usage
$ nuxt generate <dir>
Options
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
--no-build Just run generate for faster builds when just dynamic routes changed. Nuxt build is needed before this command.
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
options.dev = false // Force production mode (no webpack middleware called)
const nuxt = new Nuxt(options)
const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
const generateOptions = {
init: true,
build: argv.build
}
generator
.generate(generateOptions)
.then(() => {
process.exit(0)
})
.catch(err => consola.fatal(err))

View File

@ -1,86 +0,0 @@
#!/usr/bin/env node
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const fs = require('fs')
const { resolve } = require('path')
const parseArgs = require('minimist')
const consola = require('consola')
const { Nuxt } = require('../dist/nuxt-start')
const { loadNuxtConfig } = require('./common/utils')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
H: 'hostname',
p: 'port',
n: 'unix-socket',
c: 'config-file',
s: 'spa',
u: 'universal'
},
boolean: ['h', 's', 'u'],
string: ['H', 'c', 'n'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.hostname === '') {
consola.fatal('Provided hostname argument has no value')
}
if (argv.help) {
process.stderr.write(`
Description
Starts the application in production mode.
The application should be compiled with \`nuxt build\` first.
Usage
$ nuxt start <dir> -p <port number> -H <hostname>
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--unix-socket, -n Path to a UNIX socket
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
// Force production mode (no webpack middleware called)
options.dev = false
const nuxt = new Nuxt(options)
// Setup hooks
nuxt.hook('error', err => consola.fatal(err))
// Check if project is built for production
const distDir = resolve(
nuxt.options.rootDir,
nuxt.options.buildDir || '.nuxt',
'dist',
'server'
)
if (!fs.existsSync(distDir)) {
consola.fatal(
'No build files found, please run `nuxt build` before launching `nuxt start`'
)
}
// Check if SSR Bundle is required
if (nuxt.options.render.ssr === true) {
const ssrBundlePath = resolve(distDir, 'server-bundle.json')
if (!fs.existsSync(ssrBundlePath)) {
consola.fatal(
'No SSR build! Please start with `nuxt start --spa` or build using `nuxt build --universal`'
)
}
}
nuxt.listen().then(() => {
nuxt.showReady(false)
})

View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

View File

@ -0,0 +1,27 @@
#!/usr/bin/env node
const register = require('@babel/register')
require('@babel/polyfill')
register({
presets: [
[ '@babel/env', { targets: { node: 'current' } } ]
],
ignore: [
(path) => {
// Transpile known packages
if (/(@nuxt|@nuxtjs)[\\/]/.test(path)) {
return false
}
// Ignore everything else inside node_modules
if (/node_modules/.test(path)) {
return true
}
// Transpile project files
return false
}
]
})
require('@nuxt/cli/bin/nuxt.js')

View File

@ -0,0 +1,23 @@
export default {
build: false,
extend(pkg, { load }) {
pkg.on('build:done', () => {
const mono = load('../..')
const nuxt = load('../nuxt')
pkg.copyFilesFrom(mono, [
'LICENSE'
])
pkg.copyFieldsFrom(nuxt, [
'license',
'repository',
'contributors',
'keywords',
'collective'
])
pkg.writePackage()
})
}
}

View File

@ -0,0 +1,67 @@
{
"name": "nuxt-legacy",
"version": "2.3.0",
"description": "Legacy build of Nuxt.js for Node.js < 8.0.0",
"keywords": [
"nuxt",
"nuxt.js",
"nuxtjs",
"ssr",
"vue",
"vue isomorphic",
"vue server side",
"vue ssr",
"vue universal",
"vue versatile",
"vue.js",
"vuejs"
],
"homepage": "https://github.com/nuxt/nuxt.js#readme",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"contributors": [
{
"name": "Sebastien Chopin (@Atinux)"
},
{
"name": "Alexandre Chopin (@alexchopin)"
},
{
"name": "Pooya Parsa (@pi0)"
},
{
"name": "Clark Du (@clarkdo)"
},
{
"name": "Jonas Galvez (@galvez)"
},
{
"name": "Alexander Lichter (@manniL}"
}
],
"files": [
"bin"
],
"bin": {
"nuxt-legacy": "bin/nuxt-legacy.js"
},
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"@nuxt/builder": "^2.3.0",
"@nuxt/cli": "^2.3.0",
"@nuxt/common": "^2.3.0",
"@nuxt/core": "^2.3.0",
"consola": "^1.4.4"
},
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"collective": {
"url": "https://opencollective.com/nuxtjs",
"logoUrl": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
}
}

View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

View File

@ -0,0 +1,23 @@
export default {
build: true,
extend(pkg, { load }) {
pkg.on('build:done', () => {
const mono = load('../..')
const nuxt = load('../nuxt')
pkg.copyFilesFrom(mono, [
'LICENSE'
])
pkg.copyFieldsFrom(nuxt, [
'license',
'repository',
'contributors',
'keywords',
'engines'
])
pkg.writePackage()
})
}
}

View File

@ -0,0 +1,56 @@
{
"name": "nuxt-start",
"version": "2.3.0",
"description": "Starts Nuxt.js Application in production mode",
"keywords": [
"nuxt",
"nuxt.js",
"nuxtjs",
"ssr",
"vue",
"vue isomorphic",
"vue server side",
"vue ssr",
"vue universal",
"vue versatile",
"vue.js",
"vuejs"
],
"homepage": "https://github.com/nuxt/nuxt.js#readme",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"contributors": [
{
"name": "Sebastien Chopin (@Atinux)"
},
{
"name": "Alexandre Chopin (@alexchopin)"
},
{
"name": "Pooya Parsa (@pi0)"
},
{
"name": "Clark Du (@clarkdo)"
},
{
"name": "Jonas Galvez (@galvez)"
},
{
"name": "Alexander Lichter (@manniL}"
}
],
"files": [
"dist"
],
"main": "dist/nuxt-start.js",
"dependencies": {
"@nuxt/cli": "^2.3.0",
"@nuxt/common": "^2.3.0",
"@nuxt/core": "^2.3.0",
"consola": "^1.4.4"
},
"engines": {
"node": ">=8.0.0",
"npm": ">=5.0.0"
}
}

View File

@ -0,0 +1 @@
export * from '@nuxt/core'

View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

View File

@ -0,0 +1,12 @@
export default {
build: true,
extend(pkg, { load }) {
pkg.on('build:done', () => {
const mono = load('../..')
pkg.copyFilesFrom(mono, [
'LICENSE'
])
})
}
}

View File

@ -0,0 +1,63 @@
{
"name": "nuxt",
"version": "2.3.0",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"keywords": [
"nuxt",
"nuxt.js",
"nuxtjs",
"ssr",
"vue",
"vue isomorphic",
"vue server side",
"vue ssr",
"vue universal",
"vue versatile",
"vue.js",
"vuejs"
],
"repository": "nuxt/nuxt.js",
"license": "MIT",
"contributors": [
{
"name": "Sebastien Chopin (@Atinux)"
},
{
"name": "Alexandre Chopin (@alexchopin)"
},
{
"name": "Pooya Parsa (@pi0)"
},
{
"name": "Clark Du (@clarkdo)"
},
{
"name": "Jonas Galvez (@galvez)"
},
{
"name": "Alexander Lichter (@manniL}"
}
],
"files": [
"dist"
],
"main": "dist/nuxt.js",
"scripts": {
"postinstall": "opencollective || exit 0"
},
"dependencies": {
"@nuxt/builder": "^2.3.0",
"@nuxt/cli": "^2.3.0",
"@nuxt/common": "^2.3.0",
"@nuxt/core": "^2.3.0",
"consola": "^1.4.4"
},
"engines": {
"node": ">=8.0.0",
"npm": ">=5.0.0"
},
"collective": {
"url": "https://opencollective.com/nuxtjs",
"logoUrl": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
}
}

View File

@ -0,0 +1,2 @@
export * from '@nuxt/core'
export * from '@nuxt/builder'

View File

@ -1,18 +0,0 @@
/*!
* Nuxt.js
* (c) 2016-2018 Chopin Brothers
* Core maintainers: Pooya Parsa (@pi0) - Clark Du (@clarkdo)
* Released under the MIT License.
*/
const fs = require('fs')
const path = require('path')
if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
// Use esm version when using linked repository to prevent builds
const requireModule = require('esm')(module, {})
module.exports = requireModule('./lib/index.js').default
} else {
// Use production bundle by default
module.exports = require('./dist/nuxt.js')
}

View File

@ -1,17 +1,42 @@
module.exports = {
testEnvironment: 'node',
coverageDirectory: './coverage/',
collectCoverageFrom: [
'lib/!(app)/**',
'!lib/builder/webpack/plugins/vue/**'
],
setupTestFrameworkScriptFile: './test/utils/setup',
testPathIgnorePatterns: ['test/fixtures/.*/.*?/'],
transformIgnorePatterns: ['<rootDir>/node_modules/'],
moduleFileExtensions: ['js', 'mjs', 'json'],
expand: true,
forceExit: true
forceExit: true,
// https://github.com/facebook/jest/pull/6747 fix warning here
// But its performance overhead is pretty bad (30+%).
// detectOpenHandles: true
setupTestFrameworkScriptFile: './test/utils/setup',
coverageDirectory: './coverage',
collectCoverageFrom: [
'packages/*/src/**/*.js',
'packages/cli/bin/*'
],
coveragePathIgnorePatterns: [
'node_modules',
'packages/app',
'packages/builder/webpack/plugins/vue'
],
testPathIgnorePatterns: [
'node_modules',
'test/fixtures/.*/.*?/',
'examples/.*'
],
transformIgnorePatterns: [
'/node_modules/',
'/dist/'
],
moduleFileExtensions: [
'js',
'json'
]
}

19
lerna.json Normal file
View File

@ -0,0 +1,19 @@
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true,
"conventionalCommits": true,
"skipGit": true,
"yes": true,
"noPush": true,
"gitTagVersion": false,
"packages": [
"packages/*",
"distributions/*"
],
"command": {
"publish": {
"npmClient": "npm"
}
}
}

View File

@ -1,7 +0,0 @@
import Builder from './builder'
import Generator from './generator'
export default {
Builder,
Generator
}

View File

@ -1 +0,0 @@
Temporary fork until [vuejs/vue#7839](https://github.com/vuejs/vue/pull/7839) arrives.

View File

@ -1,9 +0,0 @@
import Module from './module'
import Nuxt from './nuxt'
import Renderer from './renderer'
export default {
Nuxt,
Module,
Renderer
}

View File

@ -1,6 +0,0 @@
import core from './core'
import builder from './builder'
import * as Utils from './common/utils'
import Options from './common/options'
export default Object.assign({ Utils, Options }, core, builder)

View File

@ -1,4 +0,0 @@
export default (pkg) => {
pkg.sortDependencies()
pkg.writePackage()
}

View File

@ -1,143 +1,24 @@
{
"name": "nuxt",
"version": "2.2.0",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"contributors": [
{
"name": "Sebastien Chopin (@Atinux)"
},
{
"name": "Alexandre Chopin (@alexchopin)"
},
{
"name": "Pooya Parsa (@pi0)"
},
{
"name": "Clark Du (@clarkdo)"
},
{
"name": "Jonas Galvez (@galvez)"
},
{
"name": "Alexander Lichter (@manniL}"
}
"private": true,
"workspaces": [
"packages/*",
"distributions/*"
],
"main": "index.js",
"module": "./lib/nuxt.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt/nuxt.js"
},
"files": [
"bin",
"lib",
"dist",
"index.js"
],
"keywords": [
"nuxt",
"nuxt.js",
"nuxtjs",
"vue",
"vue.js",
"vuejs",
"vue universal",
"vue ssr",
"vue server side",
"ssr",
"vue isomorphic",
"vue versatile"
],
"homepage": "https://github.com/nuxt/nuxt.js#readme",
"bin": {
"nuxt": "./bin/nuxt"
},
"scripts": {
"build": "node -r esm ./packages/nuxt-pack/build.js",
"build": "node -r esm ./scripts/package",
"dev": "yarn build --watch",
"coverage": "codecov",
"lint": "eslint --ext .js,.mjs,.vue bin/** benchmarks examples lib packages test",
"postinstall": "opencollective || exit 0",
"lint": "eslint --ext .js,.mjs,.vue .",
"nuxt": "node -r esm ./packages/cli/bin/nuxt.js",
"test": "yarn test:fixtures && yarn test:unit",
"test:fixtures": "jest test/fixtures",
"test:e2e": "jest -i test/e2e",
"test:lint": "yarn lint",
"test:unit": "jest test/unit"
},
"engines": {
"node": ">=8.0.0",
"npm": ">=5.0.0"
},
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/polyfill": "^7.0.0",
"@nuxtjs/babel-preset-app": "^0.7.0",
"@nuxtjs/devalue": "^1.0.1",
"@nuxtjs/friendly-errors-webpack-plugin": "^2.0.2",
"@nuxtjs/opencollective": "^0.1.0",
"@nuxtjs/youch": "^4.2.3",
"babel-loader": "^8.0.4",
"cache-loader": "^1.2.2",
"caniuse-lite": "^1.0.30000892",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"compression": "^1.7.3",
"connect": "^3.6.6",
"consola": "^1.4.4",
"css-loader": "^1.0.0",
"cssnano": "^4.1.4",
"debug": "^4.1.0",
"esm": "^3.0.84",
"etag": "^1.8.1",
"file-loader": "^2.0.0",
"fresh": "^0.5.2",
"fs-extra": "^7.0.0",
"glob": "^7.1.3",
"hash-sum": "^1.0.2",
"html-minifier": "^3.5.20",
"html-webpack-plugin": "^3.2.0",
"ip": "^1.1.5",
"launch-editor-middleware": "^2.2.1",
"lodash": "^4.17.11",
"lru-cache": "^4.1.3",
"memory-fs": "^0.4.1",
"mini-css-extract-plugin": "^0.4.4",
"minimist": "^1.2.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"pify": "^4.0.0",
"postcss": "^7.0.5",
"postcss-import": "^12.0.0",
"postcss-import-resolver": "^1.1.0",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.1.1",
"postcss-url": "^8.0.0",
"semver": "^5.6.0",
"serialize-javascript": "^1.5.0",
"serve-static": "^1.13.2",
"server-destroy": "^1.0.1",
"std-env": "^2.0.2",
"style-resources-loader": "^1.2.1",
"terser-webpack-plugin": "^1.1.0",
"thread-loader": "^1.2.0",
"time-fix-plugin": "^2.0.4",
"upath": "^1.1.0",
"url-loader": "^1.1.2",
"vue": "^2.5.17",
"vue-loader": "^15.4.2",
"vue-meta": "^1.5.5",
"vue-no-ssr": "^1.0.0",
"vue-router": "^3.0.1",
"vue-server-renderer": "^2.5.17",
"vue-template-compiler": "^2.5.17",
"vuex": "^3.0.1",
"webpack": "^4.20.2",
"webpack-bundle-analyzer": "^3.0.2",
"webpack-dev-middleware": "^3.4.0",
"webpack-hot-middleware": "^2.24.3",
"webpack-node-externals": "^1.7.2",
"webpackbar": "^2.6.3"
"test:unit": "jest test/unit",
"postinstall": "lerna link"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@nuxtjs/eslint-config": "^0.0.1",
"babel-core": "^7.0.0-bridge",
@ -145,6 +26,7 @@
"babel-jest": "^23.6.0",
"babel-plugin-dynamic-import-node": "^2.2.0",
"codecov": "^3.1.0",
"consola": "^1.4.4",
"cross-env": "^5.2.0",
"cross-spawn": "^6.0.5",
"eslint": "^5.7.0",
@ -155,12 +37,17 @@
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.0.0-beta.3",
"esm": "^3.0.84",
"express": "^4.16.4",
"finalhandler": "^1.1.1",
"fs-extra": "^7.0.0",
"get-port": "^4.0.0",
"glob": "^7.1.3",
"jest": "^23.6.0",
"jsdom": "^12.2.0",
"klaw-sync": "^6.0.0",
"lerna": "^3.4.3",
"lodash": "^4.17.11",
"pug": "^2.0.3",
"pug-plain-loader": "^1.0.0",
"puppeteer": "^1.9.0",
@ -168,13 +55,12 @@
"request-promise-native": "^1.0.5",
"rimraf": "^2.6.2",
"rollup": "^0.66.6",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-license": "^0.7.0"
},
"collective": {
"url": "https://opencollective.com/nuxtjs",
"logoUrl": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
"rollup-plugin-license": "^0.7.0",
"rollup-plugin-replace": "^2.1.0",
"sort-package-json": "^1.16.0"
}
}

11
packages/app/CHANGELOG.md Normal file
View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

3
packages/app/package.js Normal file
View File

@ -0,0 +1,3 @@
export default {
build: true
}

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

@ -0,0 +1,11 @@
{
"name": "@nuxt/app",
"version": "2.3.0",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"files": [
"dist",
"template"
],
"main": "dist/app.js"
}

25
packages/app/src/index.js Normal file
View File

@ -0,0 +1,25 @@
import path from 'path'
import pkg from '../package.json'
export const meta = pkg
export const templatesDir = path.join(__dirname, '..', 'template')
export const templatesFiles = [
'App.js',
'client.js',
'index.js',
'middleware.js',
'router.js',
'server.js',
'utils.js',
'empty.js',
'components/nuxt-error.vue',
'components/nuxt-loading.vue',
'components/nuxt-child.js',
'components/nuxt-link.js',
'components/nuxt.js',
'components/no-ssr.js',
'views/app.template.html',
'views/error.html'
]

View File

@ -91,7 +91,7 @@ async function createApp (ssrContext) {
const nuxt = this.nuxt || this.$options.nuxt
nuxt.dateErr = Date.now()
nuxt.err = err
// Used in lib/server.js
// Used in src/server.js
if (ssrContext) ssrContext.nuxt.error = err
return err
}

View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

View File

@ -0,0 +1,3 @@
export default {
build: true
}

View File

@ -0,0 +1,58 @@
{
"name": "@nuxt/builder",
"version": "2.3.0",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"files": [
"dist"
],
"main": "dist/builder.js",
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/polyfill": "^7.0.0",
"@nuxt/app": "^2.3.0",
"@nuxt/common": "^2.3.0",
"@nuxtjs/babel-preset-app": "^0.7.0",
"@nuxtjs/devalue": "^1.0.1",
"@nuxtjs/friendly-errors-webpack-plugin": "^2.0.2",
"babel-loader": "^8.0.4",
"cache-loader": "^1.2.2",
"caniuse-lite": "^1.0.30000892",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"consola": "^1.4.4",
"css-loader": "^1.0.0",
"cssnano": "^4.1.4",
"file-loader": "^2.0.0",
"fs-extra": "^7.0.0",
"glob": "^7.1.3",
"hash-sum": "^1.0.2",
"html-minifier": "^3.5.20",
"html-webpack-plugin": "^3.2.0",
"lodash": "^4.17.11",
"memory-fs": "^0.4.1",
"mini-css-extract-plugin": "^0.4.3",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"pify": "^4.0.0",
"postcss": "^7.0.5",
"postcss-import": "^12.0.0",
"postcss-import-resolver": "^1.1.0",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.0.10",
"postcss-url": "^8.0.0",
"serialize-javascript": "^1.5.0",
"style-resources-loader": "^1.2.1",
"terser-webpack-plugin": "^1.1.0",
"thread-loader": "^1.2.0",
"time-fix-plugin": "^2.0.4",
"upath": "^1.1.0",
"url-loader": "^1.1.1",
"vue-loader": "^15.4.2",
"webpack": "^4.20.2",
"webpack-bundle-analyzer": "^3.0.2",
"webpack-dev-middleware": "^3.4.0",
"webpack-hot-middleware": "^2.24.3",
"webpack-node-externals": "^1.7.2",
"webpackbar": "^2.6.3"
}
}

View File

@ -1,6 +1,5 @@
import path from 'path'
import fs from 'fs'
import pify from 'pify'
import _ from 'lodash'
import chokidar from 'chokidar'
@ -8,7 +7,6 @@ import fsExtra from 'fs-extra'
import hash from 'hash-sum'
import webpack from 'webpack'
import serialize from 'serialize-javascript'
import devalue from '@nuxtjs/devalue'
import MFS from 'memory-fs'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
@ -16,7 +14,10 @@ import Glob from 'glob'
import upath from 'upath'
import consola from 'consola'
import devalue from '@nuxtjs/devalue'
import {
Options,
r,
wp,
wChunk,
@ -26,9 +27,8 @@ import {
relativeTo,
waitFor,
determineGlobals
} from '../common/utils'
} from '@nuxt/common'
import Options from '../common/options'
import PerfLoader from './webpack/utils/perf-loader'
import ClientWebpackConfig from './webpack/client'
import ServerWebpackConfig from './webpack/server'
@ -79,6 +79,12 @@ export default class Builder {
})
}
// Resolve template
this.template = this.options.build.template || '@nuxt/app'
if (typeof this.template === 'string') {
this.template = this.nuxt.resolver.requireModule(this.template)
}
// if(!this.options.dev) {
// TODO: enable again when unsafe concern resolved.(common/options.js:42)
// this.nuxt.hook('build:done', () => this.generateConfig())
@ -94,7 +100,7 @@ export default class Builder {
''
)
return {
src: this.nuxt.resolveAlias(p.src),
src: this.nuxt.resolver.resolveAlias(p.src),
ssr: p.ssr !== false,
name: 'nuxt_plugin_' + pluginBaseName + '_' + hash(p.src)
}
@ -190,24 +196,8 @@ export default class Builder {
this.plugins = this.normalizePlugins()
// -- Templates --
let templatesFiles = [
'App.js',
'client.js',
'index.js',
'middleware.js',
'router.js',
'server.js',
'utils.js',
'empty.js',
'components/nuxt-error.vue',
'components/nuxt-loading.vue',
'components/nuxt-child.js',
'components/nuxt-link.js',
'components/nuxt.js',
'components/no-ssr.js',
'views/app.template.html',
'views/error.html'
]
let templatesFiles = Array.from(this.template.templatesFiles)
const templateVars = {
options: this.options,
extensions: this.options.extensions
@ -286,7 +276,7 @@ export default class Builder {
if (this._defaultPage) {
templateVars.router.routes = createRoutes(
['index.vue'],
this.options.nuxtAppDir + '/pages'
this.template.templatesDir + '/pages'
)
} else if (this._nuxtPages) { // If user defined a custom method to create routes
// Use nuxt.js createRoutes bases on pages/
@ -354,7 +344,7 @@ export default class Builder {
const customFileExists = fsExtra.existsSync(customPath)
return {
src: customFileExists ? customPath : r(this.options.nuxtAppDir, file),
src: customFileExists ? customPath : r(this.template.templatesDir, file),
dst: file,
custom: customFileExists
}
@ -379,11 +369,11 @@ export default class Builder {
// -- Loading indicator --
if (this.options.loadingIndicator.name) {
const indicatorPath1 = path.resolve(
this.options.nuxtAppDir,
this.template.templatesDir,
'views/loading',
this.options.loadingIndicator.name + '.html'
)
const indicatorPath2 = this.nuxt.resolveAlias(
const indicatorPath2 = this.nuxt.resolver.resolveAlias(
this.options.loadingIndicator.name
)
const indicatorPath = fsExtra.existsSync(indicatorPath1)
@ -429,8 +419,8 @@ export default class Builder {
r,
wp,
wChunk,
resolvePath: this.nuxt.resolvePath,
resolveAlias: this.nuxt.resolveAlias,
resolvePath: this.nuxt.resolver.resolvePath,
resolveAlias: this.nuxt.resolver.resolveAlias,
relativeToBuild: this.relativeToBuild
},
interpolate: /<%=([\s\S]+?)%>/g
@ -672,8 +662,8 @@ export default class Builder {
const nuxtRestartWatch = _.concat(
this.options.serverMiddleware
.filter(i => typeof i === 'string')
.map(this.nuxt.resolveAlias),
this.options.watch.map(this.nuxt.resolveAlias),
.map(this.nuxt.resolver.resolveAlias),
this.options.watch.map(this.nuxt.resolver.resolveAlias),
path.join(this.options.rootDir, 'nuxt.config.js')
)

View File

@ -3,7 +3,8 @@ import htmlMinifier from 'html-minifier'
import Chalk from 'chalk'
import fsExtra from 'fs-extra'
import consola from 'consola'
import { flatRoutes, isUrl, promisifyRoute, waitFor, isString } from '../common/utils'
import { flatRoutes, isUrl, promisifyRoute, waitFor, isString } from '@nuxt/common'
export default class Generator {
constructor(nuxt, builder) {

View File

@ -0,0 +1,2 @@
export { default as Builder } from './builder'
export { default as Generator } from './generator'

View File

@ -1,13 +1,13 @@
import path from 'path'
import consola from 'consola'
import TimeFixPlugin from 'time-fix-plugin'
import _ from 'lodash'
import VueLoader from 'vue-loader'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import WebpackBar from 'webpackbar'
import { isUrl, urlJoin } from '../../common/utils'
import { isUrl, urlJoin } from '@nuxt/common'
import StyleLoader from './utils/style-loader'
import WarnFixPlugin from './plugins/warnfix'
import StatsPlugin from './plugins/stats'

View File

@ -1,5 +1,4 @@
import path from 'path'
import webpack from 'webpack'
import HTMLPlugin from 'html-webpack-plugin'
import BundleAnalyzer from 'webpack-bundle-analyzer'

View File

@ -1,5 +1,6 @@
import hash from 'hash-sum'
import { uniq } from 'lodash'
import { isJS, isCSS, onEmit } from './util'
export default class VueSSRClientPlugin {

View File

@ -1,6 +1,5 @@
import path from 'path'
import fs from 'fs'
import webpack from 'webpack'
import nodeExternals from 'webpack-node-externals'

View File

@ -1,10 +1,9 @@
import fs from 'fs'
import path from 'path'
import _ from 'lodash'
import createResolver from 'postcss-import-resolver'
import { isPureObject } from '../../../common/utils'
import { isPureObject } from '@nuxt/common'
export default class PostcssConfig {
constructor(options, nuxt) {

View File

@ -1,5 +1,7 @@
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { wrapArray } from '../../../common/utils'
import { wrapArray } from '@nuxt/common'
import PostcssConfig from './postcss'
export default class StyleLoader {

11
packages/cli/CHANGELOG.md Normal file
View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

View File

@ -1,10 +1,12 @@
#!/usr/bin/env node
const { join } = require('path')
const consola = require('consola')
const cli = require('../dist/cli.js')
// Global error handler
process.on('unhandledRejection', err => consola.error(err))
process.on('unhandledRejection', (err) => {
consola.error(err)
})
// Exit process on fatal errors
consola.add({
@ -17,7 +19,12 @@ consola.add({
})
const defaultCommand = 'dev'
const commands = new Set([defaultCommand, 'init', 'build', 'start', 'generate'])
const commands = new Set([
defaultCommand,
'build',
'start',
'generate'
])
let cmd = process.argv[2]
@ -27,6 +34,11 @@ if (commands.has(cmd)) {
cmd = defaultCommand
}
const bin = join(__dirname, 'nuxt-' + cmd)
// Apply default NODE_ENV if not provided
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = cmd === 'dev' ? 'development' : 'production'
}
require(bin)
cli[cmd]().then(m => m.default()).catch((error) => {
consola.fatal(error)
})

3
packages/cli/package.js Normal file
View File

@ -0,0 +1,3 @@
export default {
build: true
}

19
packages/cli/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "@nuxt/cli",
"version": "2.3.0",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"files": [
"bin",
"dist"
],
"main": "dist/cli.js",
"bin": {
"nuxt": "bin/nuxt.js"
},
"dependencies": {
"consola": "^1.4.4",
"esm": "^3.0.84",
"minimist": "^1.2.0"
}
}

View File

@ -0,0 +1,90 @@
import parseArgs from 'minimist'
import consola from 'consola'
import { loadNuxtConfig } from '../common/utils'
export default async function build() {
const { Nuxt } = await import('@nuxt/core')
const { Builder, Generator } = await import('@nuxt/builder')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
c: 'config-file',
a: 'analyze',
s: 'spa',
u: 'universal',
q: 'quiet'
},
boolean: ['h', 'a', 's', 'u', 'q'],
string: ['c'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.help) {
process.stderr.write(`
Description
Compiles the application for production deployment
Usage
$ nuxt build <dir>
Options
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
--spa, -s Launch in SPA mode
--universal, -u Launch in Universal mode (default)
--no-generate Don't generate static version for SPA mode (useful for nuxt start)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--quiet, -q Disable output except for errors
--help, -h Displays this message
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
// Create production build when calling `nuxt build`
options.dev = false
// Analyze option
options.build = options.build || {}
if (argv.analyze && typeof options.build.analyze !== 'object') {
options.build.analyze = true
}
// Silence output when using --quiet
if (argv.quiet) {
options.build.quiet = !!argv.quiet
}
const nuxt = new Nuxt(options)
const builder = new Builder(nuxt)
// Setup hooks
nuxt.hook('error', err => consola.fatal(err))
// Close function
const close = () => {
// In analyze mode wait for plugin
// emitting assets and opening browser
if (options.build.analyze === true || typeof options.build.analyze === 'object') {
return
}
process.exit(0)
}
if (options.mode !== 'spa' || argv.generate === false) {
// Build only
return builder
.build()
.then(close)
.catch(err => consola.fatal(err))
} else {
// Build + Generate for static deployment
return new Generator(nuxt, builder)
.generate({ build: true })
.then(close)
.catch(err => consola.fatal(err))
}
}

View File

@ -0,0 +1,100 @@
import parseArgs from 'minimist'
import consola from 'consola'
import { loadNuxtConfig } from '../common/utils'
export default async function dev() {
const { Nuxt } = await import('@nuxt/core')
const { Builder } = await import('@nuxt/builder')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
H: 'hostname',
p: 'port',
c: 'config-file',
s: 'spa',
u: 'universal',
v: 'version'
},
boolean: ['h', 's', 'u', 'v'],
string: ['H', 'c'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.version) {
process.stderr.write('TODO' + '\n')
process.exit(0)
}
if (argv.hostname === '') {
consola.fatal('Provided hostname argument has no value')
}
if (argv.help) {
process.stderr.write(`
Description
Starts the application in development mode (hot-code reloading, error
reporting, etc)
Usage
$ nuxt dev <dir> -p <port number> -H <hostname>
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
`)
process.exit(0)
}
const config = () => {
// Force development mode for add hot reloading and watching changes
return Object.assign(loadNuxtConfig(argv), { dev: true })
}
const errorHandler = (err, instance) => {
instance && instance.builder.watchServer()
consola.error(err)
}
// Start dev
(function startDev(oldInstance) {
let nuxt, builder
try {
nuxt = new Nuxt(config())
builder = new Builder(nuxt)
nuxt.hook('watch:fileChanged', (builder, fname) => {
consola.debug(`[${fname}] changed, Rebuilding the app...`)
startDev({ nuxt: builder.nuxt, builder })
})
} catch (err) {
return errorHandler(err, oldInstance)
}
return (
Promise.resolve()
.then(() => oldInstance && oldInstance.nuxt.clearHook('watch:fileChanged'))
.then(() => oldInstance && oldInstance.builder.unwatch())
// Start build
.then(() => builder.build())
// Close old nuxt no mater if build successfully
.catch((err) => {
oldInstance && oldInstance.nuxt.close()
// Jump to eventHandler
throw err
})
.then(() => oldInstance && oldInstance.nuxt.close())
// Start listening
.then(() => nuxt.listen())
// Show ready message first time, others will be shown through WebpackBar
.then(() => !oldInstance && nuxt.showReady(false))
.then(() => builder.watchServer())
// Handle errors
.catch(err => errorHandler(err, { builder, nuxt }))
)
})()
}

View File

@ -0,0 +1,60 @@
import parseArgs from 'minimist'
import consola from 'consola'
import { loadNuxtConfig } from '../common/utils'
export default async function generate() {
const { Nuxt } = await import('@nuxt/core')
const { Builder, Generator } = await import('@nuxt/builder')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
c: 'config-file',
s: 'spa',
u: 'universal'
},
boolean: ['h', 's', 'u', 'build'],
string: ['c'],
default: {
c: 'nuxt.config.js',
build: true
}
})
if (argv.help) {
process.stderr.write(`
Description
Generate a static web application (server-rendered)
Usage
$ nuxt generate <dir>
Options
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
--no-build Just run generate for faster builds when just dynamic routes changed. Nuxt build is needed before this command.
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
options.dev = false // Force production mode (no webpack middleware called)
const nuxt = new Nuxt(options)
const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
const generateOptions = {
init: true,
build: argv.build
}
return generator
.generate(generateOptions)
.then(() => {
process.exit(0)
})
.catch(err => consola.fatal(err))
}

View File

@ -0,0 +1,87 @@
import fs from 'fs'
import path from 'path'
import parseArgs from 'minimist'
import consola from 'consola'
import { loadNuxtConfig } from '../common/utils'
export default async function start() {
const { Nuxt } = await import('@nuxt/core')
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
H: 'hostname',
p: 'port',
n: 'unix-socket',
c: 'config-file',
s: 'spa',
u: 'universal'
},
boolean: ['h', 's', 'u'],
string: ['H', 'c', 'n'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.hostname === '') {
consola.fatal('Provided hostname argument has no value')
}
if (argv.help) {
process.stderr.write(`
Description
Starts the application in production mode.
The application should be compiled with \`nuxt build\` first.
Usage
$ nuxt start <dir> -p <port number> -H <hostname>
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--unix-socket, -n Path to a UNIX socket
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
// Force production mode (no webpack middleware called)
options.dev = false
const nuxt = new Nuxt(options)
// Setup hooks
nuxt.hook('error', err => consola.fatal(err))
// Check if project is built for production
const distDir = path.resolve(
nuxt.options.rootDir,
nuxt.options.buildDir || '.nuxt',
'dist',
'server'
)
if (!fs.existsSync(distDir)) {
consola.fatal(
'No build files found, please run `nuxt build` before launching `nuxt start`'
)
}
// Check if SSR Bundle is required
if (nuxt.options.render.ssr === true) {
const ssrBundlePath = path.resolve(distDir, 'server-bundle.json')
if (!fs.existsSync(ssrBundlePath)) {
consola.fatal(
'No SSR build! Please start with `nuxt start --spa` or build using `nuxt build --universal`'
)
}
}
return nuxt.listen().then(() => {
nuxt.showReady(false)
})
}

View File

@ -1,8 +1,10 @@
const { resolve } = require('path')
const { existsSync } = require('fs')
const consola = require('consola')
const esm = require('esm')(module, {
import path from 'path'
import { existsSync } from 'fs'
import consola from 'consola'
import esm from 'esm'
const _require = esm(module, {
cache: false,
cjs: {
cache: true,
@ -11,8 +13,8 @@ const esm = require('esm')(module, {
}
})
const getRootDir = argv => resolve(argv._[0] || '.')
const getNuxtConfigFile = argv => resolve(getRootDir(argv), argv['config-file'])
const getRootDir = argv => path.resolve(argv._[0] || '.')
const getNuxtConfigFile = argv => path.resolve(getRootDir(argv), argv['config-file'])
const getLatestHost = (argv) => {
const port =
argv.port ||
@ -32,9 +34,7 @@ const getLatestHost = (argv) => {
return { port, host, socket }
}
exports.nuxtConfigFile = getNuxtConfigFile
exports.loadNuxtConfig = (argv) => {
export function loadNuxtConfig(argv) {
const rootDir = getRootDir(argv)
const nuxtConfigFile = getNuxtConfigFile(argv)
@ -42,7 +42,7 @@ exports.loadNuxtConfig = (argv) => {
if (existsSync(nuxtConfigFile)) {
delete require.cache[nuxtConfigFile]
options = esm(nuxtConfigFile)
options = _require(nuxtConfigFile)
if (!options) {
options = {}
}

View File

@ -0,0 +1,5 @@
export const start = () => import('./commands/start')
export const dev = () => import('./commands/dev')
export const build = () => import('./commands/build')
export const generate = () => import('./commands/generate')

View File

@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# 2.3.0 (2018-10-17)
### Features
* Migrate Nuxt into monorepo

View File

@ -0,0 +1,3 @@
export default {
build: true
}

View File

@ -0,0 +1,15 @@
{
"name": "@nuxt/common",
"version": "2.3.0",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"files": [
"dist"
],
"main": "dist/common.js",
"dependencies": {
"consola": "^1.4.4",
"lodash": "^4.17.11",
"std-env": "^2.0.2"
}
}

View File

@ -0,0 +1,4 @@
export { default as Modes } from './modes'
export { default as NuxtConfig } from './nuxt.config'
export { default as Options } from './options'
export * from './utils'

Some files were not shown because too many files have changed in this diff Show More