Add watchers option and url after build

This commit is contained in:
Sébastien Chopin 2017-03-25 15:16:07 +01:00
parent c9784651e9
commit 1cefff8194
5 changed files with 24 additions and 7 deletions

View File

@ -63,6 +63,6 @@ function listenOnConfigChanges (nuxt, server) {
})
}, 200)
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
chokidar.watch(nuxtConfigFile, { ignoreInitial: true })
chokidar.watch(nuxtConfigFile, Object.assign({}, nuxt.options.watchers.chokidar, { ignoreInitial: true }))
.on('all', build)
}

View File

@ -7,6 +7,7 @@ import fs from 'fs-extra'
import hash from 'hash-sum'
import pify from 'pify'
import webpack from 'webpack'
import PostCompilePlugin from 'post-compile-webpack-plugin'
import serialize from 'serialize-javascript'
import { createBundleRenderer } from 'vue-server-renderer'
import { join, resolve, sep } from 'path'
@ -370,11 +371,18 @@ function getWebpackServerConfig () {
function createWebpackMiddleware () {
const clientConfig = getWebpackClientConfig.call(this)
const host = process.env.HOST || process.env.npm_package_config_nuxt_port || '127.0.0.1'
const port = process.env.PORT || process.env.npm_package_config_nuxt_host || '3000'
// setup on the fly compilation + hot-reload
clientConfig.entry.app = _.flatten(['webpack-hot-middleware/client?reload=true', clientConfig.entry.app])
clientConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
new webpack.NoEmitOnErrorsPlugin(),
new PostCompilePlugin(stats => {
if (!stats.hasErrors() && !stats.hasWarnings()) {
console.log(`> Open http://${host}:${port}\n`) // eslint-disable-line no-console
}
})
)
const clientCompiler = webpack(clientConfig)
// Add the middleware to the instance context
@ -382,7 +390,8 @@ function createWebpackMiddleware () {
publicPath: clientConfig.output.publicPath,
stats: webpackStats,
quiet: true,
noInfo: true
noInfo: true,
watchOptions: this.options.watchers.webpack
}))
this.webpackHotMiddleware = pify(require('webpack-hot-middleware')(clientCompiler, {
log: () => {}
@ -406,7 +415,7 @@ function webpackWatchAndUpdate () {
const serverCompiler = webpack(serverConfig)
const outputPath = join(serverConfig.output.path, 'server-bundle.json')
serverCompiler.outputFileSystem = mfs
this.webpackServerWatcher = serverCompiler.watch({}, (err) => {
this.webpackServerWatcher = serverCompiler.watch(this.options.watchers.webpack, (err) => {
if (err) throw err
createRenderer.call(this, JSON.parse(mfs.readFileSync(outputPath, 'utf-8')))
})
@ -471,9 +480,9 @@ function watchPages () {
r(this.srcDir, 'layouts/*.vue'),
r(this.srcDir, 'layouts/**/*.vue')
]
const options = {
const options = Object.assign({}, this.options.watchers.chokidar, {
ignoreInitial: true
}
})
/* istanbul ignore next */
const refreshFiles = _.debounce(() => {
co(generateRoutesAndFiles.bind(this))

View File

@ -46,6 +46,10 @@ class Nuxt {
},
prefetch: true
},
watchers: {
webpack: {},
chokidar: {}
},
build: {}
}
// Sanitization

View File

@ -15,7 +15,7 @@ class Server {
}
listen (port, host) {
host = host || 'localhost'
host = host || '127.0.0.1'
port = port || 3000
this.server.listen(port, host, () => {
console.log('Ready on http://%s:%s', host, port) // eslint-disable-line no-console

View File

@ -4347,6 +4347,10 @@ pluralize@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-1.2.1.tgz#d1a21483fd22bb41e58a12fa3421823140897c45"
post-compile-webpack-plugin:
version "0.1.1"
resolved "https://registry.yarnpkg.com/post-compile-webpack-plugin/-/post-compile-webpack-plugin-0.1.1.tgz#1b1a0eea890ce748556ca49e066a48c900e0b370"
postcss-calc@^5.2.0:
version "5.3.1"
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-5.3.1.tgz#77bae7ca928ad85716e2fda42f261bf7c1d65b5e"