refactor: dev mode

This commit is contained in:
NGPixel 2018-01-27 00:20:49 -05:00
parent 1be3234ba1
commit f0e45ece6f
9 changed files with 92 additions and 31 deletions

View File

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

View File

@ -1,19 +1,28 @@
const webpack = require('webpack') const webpack = require('webpack')
const merge = require('webpack-merge') const merge = require('webpack-merge')
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin') const ExtractTextPlugin = require('extract-text-webpack-plugin')
const common = require('./webpack.common.js') const common = require('./webpack.common.js')
module.exports = merge(common, { module.exports = merge(common, {
module: { entry: {
rules: [] client: ['./client/index.js', 'webpack-hot-middleware/client']
},
output: {
pathinfo: true,
publicPath: '/'
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development') '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
}) })

View File

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

View File

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

View File

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

View File

@ -64,7 +64,9 @@ module.exports = {
}) })
cluster.on('exit', (worker, code, signal) => { 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.`)
}
}) })
}, },
/** /**

View File

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

51
wiki.js
View File

@ -11,6 +11,7 @@ const fs = Promise.promisifyAll(require('fs-extra'))
const pm2 = Promise.promisifyAll(require('pm2')) const pm2 = Promise.promisifyAll(require('pm2'))
const ora = require('ora') const ora = require('ora')
const path = require('path') const path = require('path')
const cluster = require('cluster')
const ROOTPATH = process.cwd() const ROOTPATH = process.cwd()
@ -61,10 +62,47 @@ const init = {
* Restart Wiki.js process(es) * Restart Wiki.js process(es)
*/ */
restart: function () { restart: function () {
let self = this return this.stop().delay(1000).then(() => {
return self.stop().delay(1000).then(() => { this.start()
self.startDetect()
}) })
},
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() init.restart()
} }
}) })
.command({
command: 'dev',
desc: 'Start in Developer Mode',
handler: argv => {
init.dev()
}
})
.recommendCommands() .recommendCommands()
.demandCommand(1, 'You must provide one of the accepted commands above.') .demandCommand(1, 'You must provide one of the accepted commands above.')
.help() .help()

View File

@ -338,6 +338,10 @@ ansi-escapes@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92" 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: ansi-regex@^2.0.0:
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" 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: dependencies:
whatwg-encoding "^1.0.1" 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: htmlparser2@^3.8.3, htmlparser2@^3.9.1:
version "3.9.2" version "3.9.2"
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.9.2.tgz#1bdf87acca0f3f9e53fa4fcceb0f4b4cbb00b338" 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" version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" 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" version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" 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" opener "^1.4.3"
ws "^4.0.0" 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: webpack-merge@4.1.1:
version "4.1.1" version "4.1.1"
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.1.tgz#f1197a0a973e69c6fbeeb6d658219aa8c0c13555" resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.1.tgz#f1197a0a973e69c6fbeeb6d658219aa8c0c13555"