mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Add watchers option and url after build
This commit is contained in:
parent
c9784651e9
commit
1cefff8194
@ -63,6 +63,6 @@ function listenOnConfigChanges (nuxt, server) {
|
|||||||
})
|
})
|
||||||
}, 200)
|
}, 200)
|
||||||
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
|
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)
|
.on('all', build)
|
||||||
}
|
}
|
||||||
|
19
lib/build.js
19
lib/build.js
@ -7,6 +7,7 @@ import fs from 'fs-extra'
|
|||||||
import hash from 'hash-sum'
|
import hash from 'hash-sum'
|
||||||
import pify from 'pify'
|
import pify from 'pify'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
|
import PostCompilePlugin from 'post-compile-webpack-plugin'
|
||||||
import serialize from 'serialize-javascript'
|
import serialize from 'serialize-javascript'
|
||||||
import { createBundleRenderer } from 'vue-server-renderer'
|
import { createBundleRenderer } from 'vue-server-renderer'
|
||||||
import { join, resolve, sep } from 'path'
|
import { join, resolve, sep } from 'path'
|
||||||
@ -370,11 +371,18 @@ function getWebpackServerConfig () {
|
|||||||
|
|
||||||
function createWebpackMiddleware () {
|
function createWebpackMiddleware () {
|
||||||
const clientConfig = getWebpackClientConfig.call(this)
|
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
|
// setup on the fly compilation + hot-reload
|
||||||
clientConfig.entry.app = _.flatten(['webpack-hot-middleware/client?reload=true', clientConfig.entry.app])
|
clientConfig.entry.app = _.flatten(['webpack-hot-middleware/client?reload=true', clientConfig.entry.app])
|
||||||
clientConfig.plugins.push(
|
clientConfig.plugins.push(
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
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)
|
const clientCompiler = webpack(clientConfig)
|
||||||
// Add the middleware to the instance context
|
// Add the middleware to the instance context
|
||||||
@ -382,7 +390,8 @@ function createWebpackMiddleware () {
|
|||||||
publicPath: clientConfig.output.publicPath,
|
publicPath: clientConfig.output.publicPath,
|
||||||
stats: webpackStats,
|
stats: webpackStats,
|
||||||
quiet: true,
|
quiet: true,
|
||||||
noInfo: true
|
noInfo: true,
|
||||||
|
watchOptions: this.options.watchers.webpack
|
||||||
}))
|
}))
|
||||||
this.webpackHotMiddleware = pify(require('webpack-hot-middleware')(clientCompiler, {
|
this.webpackHotMiddleware = pify(require('webpack-hot-middleware')(clientCompiler, {
|
||||||
log: () => {}
|
log: () => {}
|
||||||
@ -406,7 +415,7 @@ function webpackWatchAndUpdate () {
|
|||||||
const serverCompiler = webpack(serverConfig)
|
const serverCompiler = webpack(serverConfig)
|
||||||
const outputPath = join(serverConfig.output.path, 'server-bundle.json')
|
const outputPath = join(serverConfig.output.path, 'server-bundle.json')
|
||||||
serverCompiler.outputFileSystem = mfs
|
serverCompiler.outputFileSystem = mfs
|
||||||
this.webpackServerWatcher = serverCompiler.watch({}, (err) => {
|
this.webpackServerWatcher = serverCompiler.watch(this.options.watchers.webpack, (err) => {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
createRenderer.call(this, JSON.parse(mfs.readFileSync(outputPath, 'utf-8')))
|
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'),
|
||||||
r(this.srcDir, 'layouts/**/*.vue')
|
r(this.srcDir, 'layouts/**/*.vue')
|
||||||
]
|
]
|
||||||
const options = {
|
const options = Object.assign({}, this.options.watchers.chokidar, {
|
||||||
ignoreInitial: true
|
ignoreInitial: true
|
||||||
}
|
})
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const refreshFiles = _.debounce(() => {
|
const refreshFiles = _.debounce(() => {
|
||||||
co(generateRoutesAndFiles.bind(this))
|
co(generateRoutesAndFiles.bind(this))
|
||||||
|
@ -46,6 +46,10 @@ class Nuxt {
|
|||||||
},
|
},
|
||||||
prefetch: true
|
prefetch: true
|
||||||
},
|
},
|
||||||
|
watchers: {
|
||||||
|
webpack: {},
|
||||||
|
chokidar: {}
|
||||||
|
},
|
||||||
build: {}
|
build: {}
|
||||||
}
|
}
|
||||||
// Sanitization
|
// Sanitization
|
||||||
|
@ -15,7 +15,7 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listen (port, host) {
|
listen (port, host) {
|
||||||
host = host || 'localhost'
|
host = host || '127.0.0.1'
|
||||||
port = port || 3000
|
port = port || 3000
|
||||||
this.server.listen(port, host, () => {
|
this.server.listen(port, host, () => {
|
||||||
console.log('Ready on http://%s:%s', host, port) // eslint-disable-line no-console
|
console.log('Ready on http://%s:%s', host, port) // eslint-disable-line no-console
|
||||||
|
@ -4347,6 +4347,10 @@ pluralize@^1.2.1:
|
|||||||
version "1.2.1"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-1.2.1.tgz#d1a21483fd22bb41e58a12fa3421823140897c45"
|
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:
|
postcss-calc@^5.2.0:
|
||||||
version "5.3.1"
|
version "5.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-5.3.1.tgz#77bae7ca928ad85716e2fda42f261bf7c1d65b5e"
|
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-5.3.1.tgz#77bae7ca928ad85716e2fda42f261bf7c1d65b5e"
|
||||||
|
Loading…
Reference in New Issue
Block a user