From 880b71047b092ed105687c7a80672ce093e2d0e4 Mon Sep 17 00:00:00 2001 From: Chris Cunniff Date: Fri, 18 Nov 2016 02:26:17 -0500 Subject: [PATCH] fixes #175, no longer sets process.env.NODE_ENV='production' or runs uglify in next dev mode (#274) --- server/build/webpack.js | 42 ++++++++++++++++++++++++----------------- server/hot-reloader.js | 5 +++-- server/index.js | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/server/build/webpack.js b/server/build/webpack.js index 99154ddbdb..871cd8c637 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -8,7 +8,7 @@ import WatchRemoveEventPlugin from './plugins/watch-remove-event-plugin' import DynamicEntryPlugin from './plugins/dynamic-entry-plugin' import DetachPlugin from './plugins/detach-plugin' -export default async function createCompiler (dir, { hotReload = false } = {}) { +export default async function createCompiler (dir, { hotReload = false, dev = false } = {}) { dir = resolve(dir) const pages = await glob('pages/**/*.js', { cwd: dir }) @@ -34,28 +34,36 @@ export default async function createCompiler (dir, { hotReload = false } = {}) { const nodeModulesDir = join(__dirname, '..', '..', '..', 'node_modules') const plugins = [ - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('production') - }), new WriteFilePlugin({ exitOnErrors: false, log: false, // required not to cache removed files useHashIndex: false }) - ].concat(hotReload ? [ - new webpack.HotModuleReplacementPlugin(), - new DetachPlugin(), - new DynamicEntryPlugin(), - new UnlinkFilePlugin(), - new WatchRemoveEventPlugin(), - new WatchPagesPlugin(dir) - ] : [ - new webpack.optimize.UglifyJsPlugin({ - compress: { warnings: false }, - sourceMap: false - }) - ]) + ] + + if (!dev) { + plugins.push( + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify('production') + }), + new webpack.optimize.UglifyJsPlugin({ + compress: { warnings: false }, + sourceMap: false + }) + ) + } + + if (hotReload) { + plugins.push( + new webpack.HotModuleReplacementPlugin(), + new DetachPlugin(), + new DynamicEntryPlugin(), + new UnlinkFilePlugin(), + new WatchRemoveEventPlugin(), + new WatchPagesPlugin(dir) + ) + } const babelRuntimePath = require.resolve('babel-runtime/package') .replace(/[\\\/]package\.json$/, '') diff --git a/server/hot-reloader.js b/server/hot-reloader.js index eb776e7fea..87227a1d7d 100644 --- a/server/hot-reloader.js +++ b/server/hot-reloader.js @@ -4,8 +4,9 @@ import webpack from './build/webpack' import read from './read' export default class HotReloader { - constructor (dir) { + constructor (dir, dev = false) { this.dir = dir + this.dev = dev this.server = null this.initialized = false this.stats = null @@ -22,7 +23,7 @@ export default class HotReloader { } async prepareServer () { - const compiler = await webpack(this.dir, { hotReload: true }) + const compiler = await webpack(this.dir, { hotReload: true, dev: this.dev }) compiler.plugin('after-emit', (compilation, callback) => { const { assets } = compilation diff --git a/server/index.js b/server/index.js index d56ab30a11..378976b12f 100644 --- a/server/index.js +++ b/server/index.js @@ -11,7 +11,7 @@ export default class Server { constructor ({ dir = '.', dev = false, hotReload = false }) { this.dir = resolve(dir) this.dev = dev - this.hotReloader = hotReload ? new HotReloader(this.dir) : null + this.hotReloader = hotReload ? new HotReloader(this.dir, this.dev) : null this.router = new Router() this.http = http.createServer((req, res) => { -- GitLab