diff --git a/build/compiler.js b/build/compiler.js index 4d162dba..4dd56b18 100644 --- a/build/compiler.js +++ b/build/compiler.js @@ -89,6 +89,7 @@ type CompilerType = { type CompilerOpts = { dir?: string, env: "production" | "development", + hmr?: boolean, watch?: boolean, forceLegacyBuild?: boolean, logger?: any, @@ -100,6 +101,7 @@ function Compiler( { dir = '.', env, + hmr = true, forceLegacyBuild, preserveNames, watch = false, @@ -132,6 +134,8 @@ function Compiler( const sharedOpts = { dir: root, + dev: env === 'development', + hmr, watch, state, fusionConfig, @@ -139,10 +143,9 @@ function Compiler( preserveNames, }; - const dev = env === 'development'; const compiler = webpack([ - getWebpackConfig({id: 'client-modern', dev, ...sharedOpts}), - getWebpackConfig({id: 'server', dev, ...sharedOpts}), + getWebpackConfig({id: 'client-modern', ...sharedOpts}), + getWebpackConfig({id: 'server', ...sharedOpts}), ]); const statsLogger = getStatsLogger({dir, logger, env}); diff --git a/build/get-webpack-config.js b/build/get-webpack-config.js index f732a62a..a675d81a 100644 --- a/build/get-webpack-config.js +++ b/build/get-webpack-config.js @@ -77,6 +77,7 @@ export type WebpackConfigOpts = {| id: $Keys, dir: string, dev: boolean, + hmr: boolean, watch: boolean, preserveNames: boolean, state: { @@ -96,7 +97,16 @@ export type WebpackConfigOpts = {| module.exports = getWebpackConfig; function getWebpackConfig(opts /*: WebpackConfigOpts */) { - const {id, dev, dir, watch, state, fusionConfig, legacyPkgConfig = {}} = opts; + const { + id, + dev, + dir, + hmr, + watch, + state, + fusionConfig, + legacyPkgConfig = {}, + } = opts; const main = 'src/main.js'; if (!fs.existsSync(path.join(dir, main))) { @@ -193,11 +203,13 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) { runtime === 'server' && path.join(__dirname, '../entries/server-public-path.js'), dev && + hmr && watch && runtime !== 'server' && `${require.resolve('webpack-hot-middleware/client')}?name=client`, // TODO(#46): use 'webpack/hot/signal' instead dev && + hmr && watch && runtime === 'server' && `${require.resolve('webpack/hot/poll')}?1000`, @@ -460,7 +472,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) { */ void 0 ), - dev && watch && new webpack.HotModuleReplacementPlugin(), + dev && hmr && watch && new webpack.HotModuleReplacementPlugin(), !dev && runtime === 'client' && new webpack.HashedModuleIdsPlugin(), runtime === 'client' && // case-insensitive paths can cause problems diff --git a/commands/dev.js b/commands/dev.js index c2cef236..569ec297 100644 --- a/commands/dev.js +++ b/commands/dev.js @@ -37,6 +37,7 @@ exports.run = async function( const compiler = new Compiler({ env: 'development', dir, + hmr, forceLegacyBuild, watch: true, logger,