refactor: dev mode

pull/621/head
NGPixel 7 years ago
parent 1be3234ba1
commit f0e45ece6f

@ -19,10 +19,8 @@ module.exports = {
},
output: {
path: path.join(process.cwd(), 'assets'),
pathinfo: true,
filename: 'js/[name].js',
chunkFilename: 'js/[name].chunk.js',
publicPath: '/'
chunkFilename: 'js/[name].chunk.js'
},
module: {
rules: [
@ -86,6 +84,7 @@ module.exports = {
loader: 'vue-loader',
options: {
extractCSS: true,
postcss: postCSSConfig,
loaders: {
css: [
{
@ -93,10 +92,6 @@ module.exports = {
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: postCSSConfig
}
],
scss: [
@ -106,10 +101,6 @@ module.exports = {
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: postCSSConfig
},
{
loader: 'sass-loader',
options: {

@ -1,19 +1,28 @@
const webpack = require('webpack')
const merge = require('webpack-merge')
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const common = require('./webpack.common.js')
module.exports = merge(common, {
module: {
rules: []
entry: {
client: ['./client/index.js', 'webpack-hot-middleware/client']
},
output: {
pathinfo: true,
publicPath: '/'
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
}),
new ExtractTextPlugin({ disable: true })
new ExtractTextPlugin({ disable: true }),
new webpack.HotModuleReplacementPlugin(),
new webpack.WatchIgnorePlugin([
/node_modules/
])
],
resolve: {}
watch: true
})

@ -7,10 +7,9 @@
"start": "node wiki start",
"stop": "node wiki stop",
"restart": "node wiki restart",
"build": "webpack --config dev/webpack/webpack.prod.js",
"build:analyze": "poi build --analyze",
"dev:client": "webpack --config dev/webpack/webpack.dev.js",
"dev:server": "nodemon",
"dev": "node wiki dev",
"build": "webpack --profile --config dev/webpack/webpack.prod.js",
"watch": "webpack --config dev/webpack/webpack.dev.js",
"test": "eslint --ext .js,.vue . && jest"
},
"bin": {
@ -204,6 +203,7 @@
"vuex-persistedstate": "2.4.2",
"webpack": "3.10.0",
"webpack-bundle-analyzer": "2.9.2",
"webpack-hot-middleware": "2.21.0",
"webpack-merge": "4.1.1",
"whatwg-fetch": "2.0.3"
},

@ -17,8 +17,6 @@ let wiki = {
}
global.wiki = wiki
process.env.VIPS_WARNING = false
// if (wiki.IS_DEBUG) {
// require('@glimpse/glimpse').init()
// }

@ -152,10 +152,10 @@ module.exports = async () => {
wiki.logger.info(`HTTP Server on port: [ ${wiki.config.port} ]`)
app.set('port', wiki.config.port)
let server = http.createServer(app)
wiki.server = http.createServer(app)
server.listen(wiki.config.port)
server.on('error', (error) => {
wiki.server.listen(wiki.config.port)
wiki.server.on('error', (error) => {
if (error.syscall !== 'listen') {
throw error
}
@ -173,7 +173,7 @@ module.exports = async () => {
}
})
server.on('listening', () => {
wiki.server.on('listening', () => {
wiki.logger.info('HTTP Server: [ RUNNING ]')
})

@ -64,7 +64,9 @@ module.exports = {
})
cluster.on('exit', (worker, code, signal) => {
wiki.logger.info(`Background Worker #${worker.id} was terminated.`)
if (!global.DEV) {
wiki.logger.info(`Background Worker #${worker.id} was terminated.`)
}
})
},
/**

@ -61,7 +61,6 @@ module.exports = Promise.join(
// ----------------------------------------
process.on('disconnect', () => {
wiki.logger.warn('Lost connection to Master. Exiting...')
process.exit()
})
})

@ -11,6 +11,7 @@ const fs = Promise.promisifyAll(require('fs-extra'))
const pm2 = Promise.promisifyAll(require('pm2'))
const ora = require('ora')
const path = require('path')
const cluster = require('cluster')
const ROOTPATH = process.cwd()
@ -61,10 +62,47 @@ const init = {
* Restart Wiki.js process(es)
*/
restart: function () {
let self = this
return self.stop().delay(1000).then(() => {
self.startDetect()
return this.stop().delay(1000).then(() => {
this.start()
})
},
dev() {
if (cluster.isMaster) {
const webpackConfig = require('./dev/webpack/webpack.dev.js')
const webpack = require('webpack')
const chokidar = require('chokidar')
let isWebpackInit = false
global.DEV = true
global.WP = webpack(webpackConfig, (err, stats) => {
if (!isWebpackInit) {
isWebpackInit = true
require('./server')
const devWatcher = chokidar.watch('./server')
devWatcher.on('ready', () => {
devWatcher.on('all', () => {
console.warn('--- >>>>>>>>>>>>>>>>>>>>>>>>>>>> ---')
console.warn('--- Changes detected: Restarting ---')
console.warn('--- <<<<<<<<<<<<<<<<<<<<<<<<<<<< ---')
global.wiki.server.close(() => {
global.wiki = {}
for (const workerId in cluster.workers) {
cluster.workers[workerId].kill()
}
Object.keys(require.cache).forEach(function(id) {
if (/[/\\]server[/\\]/.test(id)) delete require.cache[id]
})
require('./server')
})
})
})
}
})
} else {
require('./server')
}
}
}
@ -94,6 +132,13 @@ require('yargs') // eslint-disable-line no-unused-expressions
init.restart()
}
})
.command({
command: 'dev',
desc: 'Start in Developer Mode',
handler: argv => {
init.dev()
}
})
.recommendCommands()
.demandCommand(1, 'You must provide one of the accepted commands above.')
.help()

@ -338,6 +338,10 @@ ansi-escapes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92"
ansi-html@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e"
ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@ -4774,6 +4778,10 @@ html-encoding-sniffer@^1.0.1:
dependencies:
whatwg-encoding "^1.0.1"
html-entities@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
htmlparser2@^3.8.3, htmlparser2@^3.9.1:
version "3.9.2"
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.9.2.tgz#1bdf87acca0f3f9e53fa4fcceb0f4b4cbb00b338"
@ -8827,7 +8835,7 @@ querystring-es3@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
querystring@0.2.0:
querystring@0.2.0, querystring@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
@ -10971,6 +10979,15 @@ webpack-bundle-analyzer@2.9.2:
opener "^1.4.3"
ws "^4.0.0"
webpack-hot-middleware@2.21.0:
version "2.21.0"
resolved "https://registry.yarnpkg.com/webpack-hot-middleware/-/webpack-hot-middleware-2.21.0.tgz#7b3c113a7a4b301c91e0749573c7aab28b414b52"
dependencies:
ansi-html "0.0.7"
html-entities "^1.2.0"
querystring "^0.2.0"
strip-ansi "^3.0.0"
webpack-merge@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.1.tgz#f1197a0a973e69c6fbeeb6d658219aa8c0c13555"

Loading…
Cancel
Save