mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Merge branch 'dev' of github.com:nuxt/nuxt.js into dev
This commit is contained in:
commit
9e433764d7
@ -4,51 +4,57 @@
|
||||
process.env.DEBUG = 'nuxt:*'
|
||||
|
||||
var fs = require('fs')
|
||||
var parseArgs = require('minimist')
|
||||
var without = require('lodash').without
|
||||
var Nuxt = require('../')
|
||||
var resolve = require('path').resolve
|
||||
|
||||
// --analyze option
|
||||
var analyzeBuild = false
|
||||
if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== -1) {
|
||||
analyzeBuild = true
|
||||
process.argv = without(process.argv, '--analyze', '-a')
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
c: 'config-file',
|
||||
a: 'analyze'
|
||||
},
|
||||
boolean: ['h', 'a'],
|
||||
string: ['c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
})
|
||||
|
||||
if (argv.help) {
|
||||
console.log(`
|
||||
Description
|
||||
Compiles the application for production deployment
|
||||
Usage
|
||||
$ nuxt build <dir>
|
||||
Options
|
||||
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
var nuxtConfigFileName = 'nuxt.config.js'
|
||||
|
||||
// --config-file option
|
||||
var indexOfConfig = false
|
||||
if (process.argv.indexOf('--config-file') !== -1) {
|
||||
indexOfConfig = process.argv.indexOf('--config-file')
|
||||
} else if (process.argv.indexOf('-c') !== -1) {
|
||||
indexOfConfig = process.argv.indexOf('-c')
|
||||
}
|
||||
|
||||
if (indexOfConfig !== false) {
|
||||
nuxtConfigFileName = process.argv.slice(indexOfConfig)[1]
|
||||
process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName)
|
||||
}
|
||||
|
||||
// Root directory parameter
|
||||
var rootDir = resolve(process.argv.slice(2)[0] || '.')
|
||||
var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName)
|
||||
var rootDir = resolve(argv._[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
var options = {}
|
||||
if (fs.existsSync(nuxtConfigFilePath)) {
|
||||
options = require(nuxtConfigFilePath)
|
||||
} else {
|
||||
console.log(`Could not locate ${nuxtConfigFilePath}`) // eslint-disable-line no-console
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
console.error(`> Could not load config file ${argv['config-file']}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
options.dev = false // Create production build when calling `nuxt build`
|
||||
|
||||
// Create production build when calling `nuxt build`
|
||||
options.dev = false
|
||||
// Analyze option
|
||||
options.build = options.build || {}
|
||||
if (analyzeBuild) {
|
||||
options.build.analyze = analyzeBuild
|
||||
if (argv.analyze) {
|
||||
options.build.analyze = true
|
||||
}
|
||||
|
||||
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
||||
|
56
bin/nuxt-dev
56
bin/nuxt-dev
@ -7,41 +7,66 @@ var _ = require('lodash')
|
||||
var debug = require('debug')('nuxt:build')
|
||||
debug.color = 2 // force green color
|
||||
var fs = require('fs')
|
||||
var parseArgs = require('minimist')
|
||||
var Nuxt = require('../')
|
||||
var chokidar = require('chokidar')
|
||||
var resolve = require('path').resolve
|
||||
var without = require('lodash').without
|
||||
|
||||
var nuxtConfigFileName = 'nuxt.config.js'
|
||||
var argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
H: 'hostname',
|
||||
p: 'port',
|
||||
c: 'config-file'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['H', 'c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
})
|
||||
|
||||
// --config-file option
|
||||
var indexOfConfig = false
|
||||
if (process.argv.indexOf('--config-file') !== -1) {
|
||||
indexOfConfig = process.argv.indexOf('--config-file')
|
||||
} else if (process.argv.indexOf('-c') !== -1) {
|
||||
indexOfConfig = process.argv.indexOf('-c')
|
||||
if (argv.hostname === '') {
|
||||
console.error(`> Provided hostname argument has no value`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (indexOfConfig !== false) {
|
||||
nuxtConfigFileName = process.argv.slice(indexOfConfig)[1]
|
||||
process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName)
|
||||
if (argv.help) {
|
||||
console.log(`
|
||||
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
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
var rootDir = resolve(process.argv.slice(2)[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, nuxtConfigFileName)
|
||||
var rootDir = resolve(argv._[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
var options = {}
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
console.error(`> Could not load config file ${argv['config-file']}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
options.dev = true // Add hot reloading and watching changes
|
||||
// Force development mode: add hot reloading and watching changes
|
||||
options.dev = true
|
||||
|
||||
var nuxt = module.exports = new Nuxt(options)
|
||||
var port = process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
var host = process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||
var port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
var host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||
var server = nuxt.server = new nuxt.Server(nuxt).listen(port, host)
|
||||
|
||||
listenOnConfigChanges(nuxt, server)
|
||||
@ -74,7 +99,6 @@ function listenOnConfigChanges(nuxt, server) {
|
||||
process.exit(1)
|
||||
})
|
||||
}, 200)
|
||||
var nuxtConfigFile = resolve(rootDir, nuxtConfigFileName)
|
||||
chokidar.watch(nuxtConfigFile, Object.assign({}, nuxt.options.watchers.chokidar, { ignoreInitial: true }))
|
||||
.on('all', build)
|
||||
}
|
||||
|
@ -4,15 +4,44 @@
|
||||
process.env.DEBUG = 'nuxt:*'
|
||||
|
||||
var fs = require('fs')
|
||||
var parseArgs = require('minimist')
|
||||
var Nuxt = require('../')
|
||||
var resolve = require('path').resolve
|
||||
|
||||
var rootDir = resolve(process.argv.slice(2)[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
|
||||
var argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
c: 'config-file'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
})
|
||||
|
||||
if (argv.help) {
|
||||
console.log(`
|
||||
Description
|
||||
Generate a static web application (server-rendered)
|
||||
Usage
|
||||
$ nuxt generate <dir>
|
||||
Options
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
var rootDir = resolve(argv._[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
var options = {}
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
console.error(`> Could not load config file ${argv['config-file']}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
|
@ -1,22 +1,69 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs')
|
||||
var parseArgs = require('minimist')
|
||||
var Nuxt = require('../')
|
||||
var resolve = require('path').resolve
|
||||
var join = require('path').join
|
||||
|
||||
var rootDir = resolve(process.argv.slice(2)[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
|
||||
var argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
H: 'hostname',
|
||||
p: 'port',
|
||||
c: 'config-file'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['H', 'c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
})
|
||||
|
||||
if (argv.hostname === '') {
|
||||
console.error(`> Provided hostname argument has no value`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (argv.help) {
|
||||
console.log(`
|
||||
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
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
var rootDir = resolve(argv._[0] || '.')
|
||||
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
||||
|
||||
var options = {}
|
||||
if (fs.existsSync(nuxtConfigFile)) {
|
||||
options = require(nuxtConfigFile)
|
||||
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
||||
console.error(`> Could not load config file ${argv['config-file']}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (typeof options.rootDir !== 'string') {
|
||||
options.rootDir = rootDir
|
||||
}
|
||||
options.dev = false // Force production mode (no webpack middleware called)
|
||||
|
||||
var buildDir = join(options.rootDir, (options.buildDir || '.nuxt'), 'dist', 'server-bundle.json')
|
||||
// Check if project is built for production
|
||||
if (!fs.existsSync(buildDir)) {
|
||||
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') // eslint-disable-line no-console
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var nuxt = module.exports = new Nuxt(options)
|
||||
var port = process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
var host = process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||
var port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||
var host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||
var server = nuxt.server = new nuxt.Server(nuxt).listen(port, host)
|
||||
|
@ -7,21 +7,13 @@ module.exports = {
|
||||
app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js
|
||||
},
|
||||
vendor: ['lodash'],
|
||||
// Loaders config (Webpack 2)
|
||||
loaders: [
|
||||
{
|
||||
test: /\.(png|jpg|gif|svg)$/,
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
limit: 100000, // 100KO
|
||||
name: 'img/[name].[ext]?[hash]'
|
||||
}
|
||||
}
|
||||
],
|
||||
extend (config, { dev }) {
|
||||
if (dev) {
|
||||
config.devtool = (dev ? 'eval-source-map' : false)
|
||||
}
|
||||
const urlLoader = config.module.rules.find((loader) => loader.loader === 'url-loader')
|
||||
// Increase limit to 100KO
|
||||
urlLoader.query.limit = 100000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,22 @@ let router
|
||||
<%= (store ? 'let store' : '') %>
|
||||
|
||||
function mapTransitions(Components, to, from) {
|
||||
const resolveTransitions = component => (typeof component.options.transition === 'function')
|
||||
? component.options.transition(to, from)
|
||||
: component.options.transition
|
||||
|
||||
const resolveRoute = route => resolveTransitions(route.matched[0].components.default)
|
||||
|
||||
return Components.map((Component) => {
|
||||
let transition = Component.options.transition
|
||||
if (typeof transition === 'function') {
|
||||
return transition(to, from)
|
||||
const transitions = Object.assign({}, to ? resolveRoute(to) : resolveTransitions(Component))
|
||||
const from_transitions = from ? resolveRoute(from) : {}
|
||||
// Combine transitions & prefer leave* transitions of from route
|
||||
Object.keys(from_transitions).forEach(key=> {
|
||||
if (from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1) {
|
||||
transitions[key] = from_transitions[key]
|
||||
}
|
||||
return transition
|
||||
})
|
||||
return transitions
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ export default {
|
||||
functional: true,
|
||||
render (h, { parent, data }) {
|
||||
data.nuxtChild = true
|
||||
|
||||
const _parent = parent
|
||||
const transitions = parent.$nuxt.nuxt.transitions
|
||||
const defaultTransition = parent.$nuxt.nuxt.defaultTransition
|
||||
let depth = 0
|
||||
@ -51,7 +51,7 @@ export default {
|
||||
let listeners = {}
|
||||
listenersKeys.forEach((key) => {
|
||||
if (typeof transition[key] === 'function') {
|
||||
listeners[key] = transition[key]
|
||||
listeners[key] = transition[key].bind(_parent)
|
||||
}
|
||||
})
|
||||
return h('transition', {
|
||||
|
29
lib/build.js
29
lib/build.js
@ -35,31 +35,13 @@ const defaults = {
|
||||
app: 'nuxt.bundle.[chunkhash].js'
|
||||
},
|
||||
vendor: [],
|
||||
loaders: [],
|
||||
plugins: [],
|
||||
babel: {},
|
||||
postcss: [],
|
||||
templates: [],
|
||||
watch: []
|
||||
}
|
||||
const defaultsLoaders = [
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)$/,
|
||||
loader: 'url-loader',
|
||||
query: {
|
||||
limit: 1000, // 1KO
|
||||
name: 'img/[name].[hash:7].[ext]'
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
||||
loader: 'url-loader',
|
||||
query: {
|
||||
limit: 1000, // 1 KO
|
||||
name: 'fonts/[name].[hash:7].[ext]'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const defaultsPostcss = [
|
||||
require('autoprefixer')({
|
||||
browsers: ['last 3 versions']
|
||||
@ -69,7 +51,6 @@ const defaultsPostcss = [
|
||||
export function options () {
|
||||
// Defaults build options
|
||||
let extraDefaults = {}
|
||||
if (this.options.build && !Array.isArray(this.options.build.loaders)) extraDefaults.loaders = defaultsLoaders
|
||||
if (this.options.build && !Array.isArray(this.options.build.postcss)) extraDefaults.postcss = defaultsPostcss
|
||||
this.options.build = _.defaultsDeep(this.options.build, defaults, extraDefaults)
|
||||
/* istanbul ignore if */
|
||||
@ -427,8 +408,9 @@ function getWebpackServerConfig () {
|
||||
|
||||
function createWebpackMiddleware () {
|
||||
const clientConfig = getWebpackClientConfig.call(this)
|
||||
const host = process.env.HOST || process.env.npm_package_config_nuxt_host || '127.0.0.1'
|
||||
const host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost'
|
||||
const port = process.env.PORT || process.env.npm_package_config_nuxt_port || '3000'
|
||||
|
||||
// setup on the fly compilation + hot-reload
|
||||
clientConfig.entry.app = _.flatten(['webpack-hot-middleware/client?reload=true', clientConfig.entry.app])
|
||||
clientConfig.plugins.push(
|
||||
@ -436,7 +418,10 @@ function createWebpackMiddleware () {
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
new PostCompilePlugin(stats => {
|
||||
if (!stats.hasErrors() && !stats.hasWarnings()) {
|
||||
console.log(`> Open http://${host}:${port}\n`) // eslint-disable-line no-console
|
||||
// We don't use os.host() here because browsers have special behaviour with localhost
|
||||
// For example chrome allows Geolocation api only to https or localhost origins
|
||||
let _host = host === '0.0.0.0' ? 'localhost' : host
|
||||
console.log(`> Open http://${_host}:${port}\n`) // eslint-disable-line no-console
|
||||
}
|
||||
})
|
||||
)
|
||||
|
@ -14,11 +14,6 @@ setAnsiColors(ansiHTML)
|
||||
export async function render (req, res) {
|
||||
// Wait for nuxt.js to be ready
|
||||
await this.ready()
|
||||
// Check if project is built for production
|
||||
if (!this.renderer && !this.dev) {
|
||||
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') // eslint-disable-line no-console
|
||||
process.exit(1)
|
||||
}
|
||||
/* istanbul ignore if */
|
||||
if (!this.renderer || !this.appTemplate) {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -46,12 +46,13 @@ class Server {
|
||||
}
|
||||
|
||||
listen (port, host) {
|
||||
host = host || '127.0.0.1'
|
||||
host = host || 'localhost'
|
||||
port = port || 3000
|
||||
this.nuxt.ready()
|
||||
.then(() => {
|
||||
this.server.listen(port, host, () => {
|
||||
console.log('Ready on http://%s:%s', host, port) // eslint-disable-line no-console
|
||||
let _host = host === '0.0.0.0' ? 'localhost' : host
|
||||
console.log('Ready on http://%s:%s', _host, port) // eslint-disable-line no-console
|
||||
})
|
||||
})
|
||||
return this
|
||||
|
@ -77,7 +77,23 @@ export default function ({ isClient, isServer }) {
|
||||
{ test: /\.less$/, use: styleLoader.call(this, 'less', 'less-loader') },
|
||||
{ test: /\.sass$/, use: styleLoader.call(this, 'sass', 'sass-loader?indentedSyntax&sourceMap') },
|
||||
{ test: /\.scss$/, use: styleLoader.call(this, 'sass', 'sass-loader?sourceMap') },
|
||||
{ test: /\.styl(us)?$/, use: styleLoader.call(this, 'stylus', 'stylus-loader') }
|
||||
{ test: /\.styl(us)?$/, use: styleLoader.call(this, 'stylus', 'stylus-loader') },
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)$/,
|
||||
loader: 'url-loader',
|
||||
query: {
|
||||
limit: 1000, // 1KO
|
||||
name: 'img/[name].[hash:7].[ext]'
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
||||
loader: 'url-loader',
|
||||
query: {
|
||||
limit: 1000, // 1 KO
|
||||
name: 'fonts/[name].[hash:7].[ext]'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: this.options.build.plugins
|
||||
@ -88,8 +104,6 @@ export default function ({ isClient, isServer }) {
|
||||
new ExtractTextPlugin({filename: this.options.build.filenames.css})
|
||||
)
|
||||
}
|
||||
// Add nuxt build loaders (can be configured in nuxt.config.js)
|
||||
config.module.rules = config.module.rules.concat(this.options.build.loaders)
|
||||
// Return config
|
||||
return config
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ export default function () {
|
||||
|
||||
// Extend config
|
||||
if (typeof this.options.build.extend === 'function') {
|
||||
this.options.build.extend(config, {
|
||||
this.options.build.extend.call(this, config, {
|
||||
dev: this.dev,
|
||||
isServer: true
|
||||
})
|
||||
|
@ -80,6 +80,7 @@
|
||||
"html-webpack-plugin": "^2.28.0",
|
||||
"lodash": "^4.17.4",
|
||||
"memory-fs": "^0.4.1",
|
||||
"minimist": "^1.2.0",
|
||||
"offline-plugin": "^4.8.1",
|
||||
"opencollective": "^1.0.3",
|
||||
"pify": "^3.0.0",
|
||||
|
Loading…
Reference in New Issue
Block a user