mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Merge branch 'dev' into feat/webpack4
This commit is contained in:
commit
46de1a32cf
43
bin/common/utils.js
Normal file
43
bin/common/utils.js
Normal file
@ -0,0 +1,43 @@
|
||||
const { Utils } = require('../..')
|
||||
const { resolve } = require('path')
|
||||
const { existsSync } = require('fs')
|
||||
|
||||
const getRootDir = argv => resolve(argv._[0] || '.')
|
||||
const getNuxtConfigFile = argv => resolve(getRootDir(argv), argv['config-file'])
|
||||
|
||||
exports.nuxtConfigFile = getNuxtConfigFile
|
||||
|
||||
exports.loadNuxtConfig = argv => {
|
||||
const rootDir = getRootDir(argv)
|
||||
const nuxtConfigFile = getNuxtConfigFile(argv)
|
||||
|
||||
let options = {}
|
||||
|
||||
if (existsSync(nuxtConfigFile)) {
|
||||
delete require.cache[nuxtConfigFile]
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
Utils.fatalError('Could not load config file: ' + argv['config-file'])
|
||||
}
|
||||
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
|
||||
// Nuxt Mode
|
||||
options.mode =
|
||||
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
exports.getLatestHost = argv => {
|
||||
const port =
|
||||
argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
const host =
|
||||
argv.hostname ||
|
||||
process.env.HOST ||
|
||||
process.env.npm_package_config_nuxt_host
|
||||
|
||||
return { port, host }
|
||||
}
|
9
bin/nuxt
9
bin/nuxt
@ -4,9 +4,10 @@
|
||||
process.env.DEBUG = process.env.DEBUG || 'nuxt:*'
|
||||
|
||||
const { join } = require('path')
|
||||
const { name, engines } = require('../package.json')
|
||||
const semver = require('semver')
|
||||
|
||||
const { Utils } = require('..')
|
||||
const { name, engines } = require('../package.json')
|
||||
|
||||
// Global error handler
|
||||
process.on('unhandledRejection', _error => {
|
||||
@ -14,7 +15,11 @@ process.on('unhandledRejection', _error => {
|
||||
})
|
||||
|
||||
if (!semver.satisfies(process.version, engines.node)) {
|
||||
Utils.fatalError(`The engine "node" is incompatible with ${name}. Expected version "${engines.node}".`)
|
||||
Utils.fatalError(
|
||||
`The engine "node" is incompatible with ${name}. Expected version "${
|
||||
engines.node
|
||||
}".`
|
||||
)
|
||||
}
|
||||
|
||||
const defaultCommand = 'dev'
|
||||
|
@ -1,13 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const fs = require('fs')
|
||||
const parseArgs = require('minimist')
|
||||
const { Nuxt, Builder, Generator, Utils } = require('..')
|
||||
const resolve = require('path').resolve
|
||||
const debug = require('debug')('nuxt:build')
|
||||
debug.color = 2 // Force green color
|
||||
|
||||
const { Nuxt, Builder, Generator, Utils } = require('..')
|
||||
const { loadNuxtConfig } = require('./common/utils')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
@ -39,26 +39,11 @@ if (argv.help) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const rootDir = resolve(argv._[0] || '.')
|
||||
const nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
var options = {}
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
Utils.fatalError(`Could not load config file`, argv['config-file'])
|
||||
}
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
const options = loadNuxtConfig(argv)
|
||||
|
||||
// Create production build when calling `nuxt build`
|
||||
options.dev = false
|
||||
|
||||
// Nuxt Mode
|
||||
options.mode =
|
||||
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
// Analyze option
|
||||
options.build = options.build || {}
|
||||
if (argv.analyze) {
|
||||
@ -86,9 +71,7 @@ if (options.mode !== 'spa') {
|
||||
.build()
|
||||
.then(() => debug('Building done'))
|
||||
.then(() => close())
|
||||
.catch(err => {
|
||||
Utils.fatalError(err)
|
||||
})
|
||||
.catch(Utils.fatalError)
|
||||
} else {
|
||||
// -- Build for SPA app --
|
||||
const s = Date.now()
|
||||
|
76
bin/nuxt-dev
76
bin/nuxt-dev
@ -1,16 +1,19 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const _ = require('lodash')
|
||||
const defaultsDeep = require('lodash/defaultsDeep')
|
||||
const debug = require('debug')('nuxt:build')
|
||||
debug.color = 2 // force green color
|
||||
const fs = require('fs')
|
||||
const parseArgs = require('minimist')
|
||||
const { Nuxt, Builder, Utils } = require('..')
|
||||
const chokidar = require('chokidar')
|
||||
const path = require('path')
|
||||
const resolve = path.resolve
|
||||
const pkg = require(path.join('..', 'package.json'))
|
||||
const { version } = require('../package.json')
|
||||
|
||||
const { Nuxt, Builder, Utils } = require('..')
|
||||
const {
|
||||
loadNuxtConfig,
|
||||
getLatestHost,
|
||||
nuxtConfigFile
|
||||
} = require('./common/utils')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
@ -30,7 +33,7 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
})
|
||||
|
||||
if (argv.version) {
|
||||
console.log(pkg.version)
|
||||
console.log(version)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
@ -56,39 +59,33 @@ if (argv.help) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const rootDir = resolve(argv._[0] || '.')
|
||||
const nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
// Load config once for chokidar
|
||||
const nuxtConfig = loadNuxtConfig()
|
||||
_.defaultsDeep(nuxtConfig, { watchers: { chokidar: { ignoreInitial: true } } })
|
||||
const nuxtConfig = loadNuxtConfig(argv)
|
||||
defaultsDeep(nuxtConfig, { watchers: { chokidar: { ignoreInitial: true } } })
|
||||
|
||||
// Start dev
|
||||
let dev = startDev()
|
||||
let needToRestart = false
|
||||
|
||||
// Start watching for nuxt.config.js changes
|
||||
chokidar.watch(nuxtConfigFile, nuxtConfig.watchers.chokidar).on('all', () => {
|
||||
debug('[nuxt.config.js] changed')
|
||||
needToRestart = true
|
||||
chokidar
|
||||
.watch(nuxtConfigFile(argv), nuxtConfig.watchers.chokidar)
|
||||
.on('all', () => {
|
||||
debug('[nuxt.config.js] changed')
|
||||
needToRestart = true
|
||||
|
||||
dev = dev.then(instance => {
|
||||
if (needToRestart === false) return instance
|
||||
needToRestart = false
|
||||
dev = dev.then(instance => {
|
||||
if (needToRestart === false) return instance
|
||||
needToRestart = false
|
||||
|
||||
debug('Rebuilding the app...')
|
||||
return startDev(instance)
|
||||
debug('Rebuilding the app...')
|
||||
return startDev(instance)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function startDev(oldInstance) {
|
||||
// Get latest environment variables
|
||||
const port =
|
||||
argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
const host =
|
||||
argv.hostname ||
|
||||
process.env.HOST ||
|
||||
process.env.npm_package_config_nuxt_host
|
||||
const { port, host } = getLatestHost(argv)
|
||||
|
||||
// Error handler
|
||||
const onError = (err, instance) => {
|
||||
@ -99,7 +96,7 @@ function startDev(oldInstance) {
|
||||
// Load options
|
||||
let options = {}
|
||||
try {
|
||||
options = loadNuxtConfig()
|
||||
options = loadAndAugmentNuxtConfig()
|
||||
} catch (err) {
|
||||
return onError(err, oldInstance)
|
||||
}
|
||||
@ -111,9 +108,9 @@ function startDev(oldInstance) {
|
||||
try {
|
||||
nuxt = new Nuxt(options)
|
||||
builder = new Builder(nuxt)
|
||||
instance = { nuxt: nuxt, builder: builder }
|
||||
instance = { nuxt, builder }
|
||||
} catch (err) {
|
||||
return onError(err, instance || oldInstance)
|
||||
return onError(err, oldInstance)
|
||||
}
|
||||
|
||||
return (
|
||||
@ -142,26 +139,11 @@ function startDev(oldInstance) {
|
||||
)
|
||||
}
|
||||
|
||||
function loadNuxtConfig() {
|
||||
let options = {}
|
||||
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
delete require.cache[nuxtConfigFile]
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
Utils.fatalError('Could not load config file: ' + argv['config-file'])
|
||||
}
|
||||
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
function loadAndAugmentNuxtConfig() {
|
||||
const options = loadNuxtConfig(argv)
|
||||
|
||||
// Force development mode for add hot reloading and watching changes
|
||||
options.dev = true
|
||||
|
||||
// Nuxt Mode
|
||||
options.mode =
|
||||
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
return options
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const fs = require('fs')
|
||||
const parseArgs = require('minimist')
|
||||
const debug = require('debug')('nuxt:generate')
|
||||
|
||||
const { Nuxt, Builder, Generator, Utils } = require('..')
|
||||
const resolve = require('path').resolve
|
||||
const { loadNuxtConfig } = require('./common/utils')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
@ -39,24 +38,10 @@ if (argv.help) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const rootDir = resolve(argv._[0] || '.')
|
||||
const nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
const options = loadNuxtConfig(argv)
|
||||
|
||||
var options = {}
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
Utils.fatalError('Could not load config file: ' + argv['config-file'])
|
||||
}
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
options.dev = false // Force production mode (no webpack middleware called)
|
||||
|
||||
// Nuxt Mode
|
||||
options.mode =
|
||||
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
debug('Generating...')
|
||||
const nuxt = new Nuxt(options)
|
||||
const builder = new Builder(nuxt)
|
||||
@ -97,6 +82,4 @@ generator
|
||||
debug('Generate done')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
Utils.fatalError(err)
|
||||
})
|
||||
.catch(Utils.fatalError)
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const parseArgs = require('minimist')
|
||||
const { Nuxt, Utils } = require('..')
|
||||
const { resolve } = require('path')
|
||||
|
||||
const { Nuxt, Utils } = require('..')
|
||||
const { loadNuxtConfig, getLatestHost } = require('./common/utils')
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
@ -44,28 +46,11 @@ if (argv.help) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const rootDir = resolve(argv._[0] || '.')
|
||||
const nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
let options = {}
|
||||
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
Utils.fatalError('Could not load config file: ' + argv['config-file'])
|
||||
}
|
||||
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
const options = loadNuxtConfig(argv)
|
||||
|
||||
// Force production mode (no webpack middleware called)
|
||||
options.dev = false
|
||||
|
||||
// Nuxt Mode
|
||||
options.mode =
|
||||
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
const nuxt = new Nuxt(options)
|
||||
|
||||
// Setup hooks
|
||||
@ -93,9 +78,6 @@ if (nuxt.options.render.ssr === true) {
|
||||
}
|
||||
}
|
||||
|
||||
const port =
|
||||
argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
const host =
|
||||
argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||
const { port, host } = getLatestHost(argv)
|
||||
|
||||
nuxt.listen(port, host)
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
** Global CSS
|
||||
*/
|
||||
css: [
|
||||
'element-ui/lib/theme-default/index.css'
|
||||
'element-ui/lib/theme-chalk/index.css'
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -3,7 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"element-ui": "^1.4.9",
|
||||
"element-ui": "^2",
|
||||
"nuxt": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import Element from 'element-ui/lib/element-ui.common'
|
||||
import Element from 'element-ui'
|
||||
import locale from 'element-ui/lib/locale/lang/en'
|
||||
|
||||
export default () => {
|
||||
|
@ -397,7 +397,7 @@ function fixPrepatch(to, ___) {
|
||||
|
||||
instances.forEach((instance, i) => {
|
||||
if (!instance) return
|
||||
if (to.matched[matches[i]].path.indexOf(':') === -1) return // If not a dyanmic route, skip
|
||||
// if (!this._queryChanged && to.matched[matches[i]].path.indexOf(':') === -1 && to.matched[matches[i]].path.indexOf('*') === -1) return // If not a dynamic route, skip
|
||||
if (instance.constructor._dataRefresh && _lastPaths[i] === instance.constructor._path && typeof instance.constructor.options.data === 'function') {
|
||||
const newData = instance.constructor.options.data.call(instance)
|
||||
for (let key in newData) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
<% if (middleware) { %>
|
||||
let files = require.context('@/<%= dir.middleware %>', false, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/)
|
||||
let files = require.context('@/<%= dir.middleware %>', false, /^\.\/(?!<%= ignorePrefix %>)[^.]+\.(<%= extensions %>)$/)
|
||||
let filenames = files.keys()
|
||||
|
||||
function getModule (filename) {
|
||||
|
@ -4,7 +4,7 @@ import Vuex from 'vuex'
|
||||
Vue.use(Vuex)
|
||||
|
||||
// Recursive find files in {srcDir}/{dir.store}
|
||||
const files = require.context('@/<%= dir.store %>', true, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/)
|
||||
const files = require.context('@/<%= dir.store %>', true, /^\.\/(?!<%= ignorePrefix %>)[^.]+\.(<%= extensions %>)$/)
|
||||
const filenames = files.keys()
|
||||
|
||||
// Store
|
||||
|
@ -672,8 +672,8 @@ module.exports = class Builder {
|
||||
|
||||
// Watch for custom provided files
|
||||
let customPatterns = _.concat(
|
||||
this.options.build.watch || [],
|
||||
_.values(_.omit(this.options.build.styleResources, 'options'))
|
||||
this.options.build.watch,
|
||||
..._.values(_.omit(this.options.build.styleResources, ['options']))
|
||||
)
|
||||
customPatterns = _.map(_.uniq(customPatterns), p =>
|
||||
upath.normalizeSafe(p)
|
||||
|
0
lib/builder/index.js
Executable file → Normal file
0
lib/builder/index.js
Executable file → Normal file
0
lib/builder/webpack/style-loader.js
Executable file → Normal file
0
lib/builder/webpack/style-loader.js
Executable file → Normal file
0
lib/common/index.js
Executable file → Normal file
0
lib/common/index.js
Executable file → Normal file
0
lib/common/options.js
Executable file → Normal file
0
lib/common/options.js
Executable file → Normal file
0
lib/core/index.js
Executable file → Normal file
0
lib/core/index.js
Executable file → Normal file
0
lib/core/module.js
Executable file → Normal file
0
lib/core/module.js
Executable file → Normal file
0
lib/index.js
Executable file → Normal file
0
lib/index.js
Executable file → Normal file
0
test/basic.ssr.test.js
Executable file → Normal file
0
test/basic.ssr.test.js
Executable file → Normal file
0
test/deprecate.test.js
Executable file → Normal file
0
test/deprecate.test.js
Executable file → Normal file
0
test/fixtures/basic/pages/async-data.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/async-data.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/css.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/css.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/head.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/head.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/stateful.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/stateful.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/stateless.vue
vendored
Executable file → Normal file
0
test/fixtures/basic/pages/stateless.vue
vendored
Executable file → Normal file
4
test/fixtures/basic/store/-ignored.js
vendored
4
test/fixtures/basic/store/-ignored.js
vendored
@ -1,3 +1 @@
|
||||
export const state = () => ({
|
||||
error: 'Should be ignored'
|
||||
})
|
||||
throw new Error('This file should be ignored!!')
|
||||
|
4
test/fixtures/basic/store/ignored.test.js
vendored
4
test/fixtures/basic/store/ignored.test.js
vendored
@ -1,3 +1 @@
|
||||
export const state = () => ({
|
||||
error: 'Should be ignored'
|
||||
})
|
||||
throw new Error('This file should be ignored!!')
|
||||
|
0
test/fixtures/basic/store/index.js
vendored
Executable file → Normal file
0
test/fixtures/basic/store/index.js
vendored
Executable file → Normal file
0
test/fixtures/deprecate/nuxt.config.js
vendored
Executable file → Normal file
0
test/fixtures/deprecate/nuxt.config.js
vendored
Executable file → Normal file
0
test/fixtures/deprecate/package.json
vendored
Executable file → Normal file
0
test/fixtures/deprecate/package.json
vendored
Executable file → Normal file
0
test/fixtures/deprecate/pages/index.vue
vendored
Executable file → Normal file
0
test/fixtures/deprecate/pages/index.vue
vendored
Executable file → Normal file
0
test/fixtures/error/nuxt.config.js
vendored
Executable file → Normal file
0
test/fixtures/error/nuxt.config.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/basic/index.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/basic/index.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/basic/reverse.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/basic/reverse.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/empty/index.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/empty/index.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/middleware/index.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/middleware/index.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/middleware/log.js
vendored
Executable file → Normal file
0
test/fixtures/module/modules/middleware/log.js
vendored
Executable file → Normal file
0
test/fixtures/module/nuxt.config.js
vendored
Executable file → Normal file
0
test/fixtures/module/nuxt.config.js
vendored
Executable file → Normal file
0
test/fixtures/module/package.json
vendored
Executable file → Normal file
0
test/fixtures/module/package.json
vendored
Executable file → Normal file
0
test/fixtures/module/views/index.vue
vendored
Executable file → Normal file
0
test/fixtures/module/views/index.vue
vendored
Executable file → Normal file
0
test/fixtures/with-config/assets/app.css
vendored
Executable file → Normal file
0
test/fixtures/with-config/assets/app.css
vendored
Executable file → Normal file
0
test/module.test.js
Executable file → Normal file
0
test/module.test.js
Executable file → Normal file
0
test/spa.test.js
Executable file → Normal file
0
test/spa.test.js
Executable file → Normal file
0
test/ssr.test.js
Executable file → Normal file
0
test/ssr.test.js
Executable file → Normal file
Loading…
Reference in New Issue
Block a user