Commit c3564cd7 authored by Mike Greiling's avatar Mike Greiling Committed by Clement Ho

Prevent webpack from rebooting while switching branches

parent 566dc70b
...@@ -21,29 +21,28 @@ var DEV_SERVER_LIVERELOAD = process.env.DEV_SERVER_LIVERELOAD !== 'false'; ...@@ -21,29 +21,28 @@ var DEV_SERVER_LIVERELOAD = process.env.DEV_SERVER_LIVERELOAD !== 'false';
var WEBPACK_REPORT = process.env.WEBPACK_REPORT; var WEBPACK_REPORT = process.env.WEBPACK_REPORT;
var NO_COMPRESSION = process.env.NO_COMPRESSION; var NO_COMPRESSION = process.env.NO_COMPRESSION;
// generate automatic entry points var autoEntriesCount = 0;
var autoEntries = {}; var watchAutoEntries = [];
var pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') });
function generateEntries() {
function generateAutoEntries(path, prefix = '.') { // generate automatic entry points
const chunkPath = path.replace(/\/index\.js$/, ''); var autoEntries = {};
const chunkName = chunkPath.replace(/\//g, '.'); var pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') });
autoEntries[chunkName] = `${prefix}/${path}`; watchAutoEntries = [
} path.join(ROOT_PATH, 'app/assets/javascripts/pages/'),
];
function generateAutoEntries(path, prefix = '.') {
const chunkPath = path.replace(/\/index\.js$/, '');
const chunkName = chunkPath.replace(/\//g, '.');
autoEntries[chunkName] = `${prefix}/${path}`;
}
pageEntries.forEach(( path ) => generateAutoEntries(path)); pageEntries.forEach(( path ) => generateAutoEntries(path));
// report our auto-generated bundle count autoEntriesCount = Object.keys(autoEntries).length;
var autoEntriesCount = Object.keys(autoEntries).length;
console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`);
var config = { const manualEntries = {
// because sqljs requires fs.
node: {
fs: "empty"
},
context: path.join(ROOT_PATH, 'app/assets/javascripts'),
entry: {
balsamiq_viewer: './blob/balsamiq_viewer.js', balsamiq_viewer: './blob/balsamiq_viewer.js',
common: './commons/index.js', common: './commons/index.js',
common_vue: './vue_shared/vue_resource_interceptor.js', common_vue: './vue_shared/vue_resource_interceptor.js',
...@@ -79,7 +78,15 @@ var config = { ...@@ -79,7 +78,15 @@ var config = {
test: './test.js', test: './test.js',
u2f: ['vendor/u2f'], u2f: ['vendor/u2f'],
webpack_runtime: './webpack.js', webpack_runtime: './webpack.js',
}, };
return Object.assign(manualEntries, autoEntries);
}
var config = {
context: path.join(ROOT_PATH, 'app/assets/javascripts'),
entry: generateEntries,
output: { output: {
path: path.join(ROOT_PATH, 'public/assets/webpack'), path: path.join(ROOT_PATH, 'public/assets/webpack'),
...@@ -296,10 +303,13 @@ var config = { ...@@ -296,10 +303,13 @@ var config = {
'vue$': 'vue/dist/vue.esm.js', 'vue$': 'vue/dist/vue.esm.js',
'spec': path.join(ROOT_PATH, 'spec/javascripts'), 'spec': path.join(ROOT_PATH, 'spec/javascripts'),
} }
} },
}
config.entry = Object.assign({}, autoEntries, config.entry); // sqljs requires fs
node: {
fs: 'empty',
},
};
if (IS_PRODUCTION) { if (IS_PRODUCTION) {
config.devtool = 'source-map'; config.devtool = 'source-map';
...@@ -336,7 +346,24 @@ if (IS_DEV_SERVER) { ...@@ -336,7 +346,24 @@ if (IS_DEV_SERVER) {
}; };
config.plugins.push( config.plugins.push(
// watch node_modules for changes if we encounter a missing module compile error // watch node_modules for changes if we encounter a missing module compile error
new WatchMissingNodeModulesPlugin(path.join(ROOT_PATH, 'node_modules')) new WatchMissingNodeModulesPlugin(path.join(ROOT_PATH, 'node_modules')),
// watch for changes to our automatic entry point modules
{
apply(compiler) {
compiler.plugin('emit', (compilation, callback) => {
compilation.contextDependencies = [
...compilation.contextDependencies,
...watchAutoEntries,
];
// report our auto-generated bundle count
console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`);
callback();
})
},
},
); );
if (DEV_SERVER_LIVERELOAD) { if (DEV_SERVER_LIVERELOAD) {
config.plugins.push(new webpack.HotModuleReplacementPlugin()); config.plugins.push(new webpack.HotModuleReplacementPlugin());
......
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"dev-server": "nodemon -w 'config/webpack.config.js' -w 'app/assets/javascripts/dispatcher.js' -w 'app/assets/javascripts/pages/**/index.js' --exec 'webpack-dev-server --config config/webpack.config.js'", "dev-server": "nodemon -w 'config/webpack.config.js' --exec 'webpack-dev-server --config config/webpack.config.js'",
"eslint": "eslint --max-warnings 0 --ext .js,.vue .", "eslint": "eslint --max-warnings 0 --ext .js,.vue .",
"eslint-fix": "eslint --max-warnings 0 --ext .js,.vue --fix .", "eslint-fix": "eslint --max-warnings 0 --ext .js,.vue --fix .",
"eslint-report": "eslint --max-warnings 0 --ext .js,.vue --format html --output-file ./eslint-report.html .", "eslint-report": "eslint --max-warnings 0 --ext .js,.vue --format html --output-file ./eslint-report.html .",
...@@ -116,6 +116,6 @@ ...@@ -116,6 +116,6 @@
"karma-webpack": "2.0.7", "karma-webpack": "2.0.7",
"nodemon": "^1.15.1", "nodemon": "^1.15.1",
"prettier": "1.9.2", "prettier": "1.9.2",
"webpack-dev-server": "^2.11.1" "webpack-dev-server": "^2.11.2"
} }
} }
...@@ -8732,9 +8732,9 @@ webpack-dev-middleware@1.12.2, webpack-dev-middleware@^1.12.0: ...@@ -8732,9 +8732,9 @@ webpack-dev-middleware@1.12.2, webpack-dev-middleware@^1.12.0:
range-parser "^1.0.3" range-parser "^1.0.3"
time-stamp "^2.0.0" time-stamp "^2.0.0"
webpack-dev-server@^2.11.1: webpack-dev-server@^2.11.2:
version "2.11.1" version "2.11.2"
resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-2.11.1.tgz#6f9358a002db8403f016e336816f4485384e5ec0" resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-2.11.2.tgz#1f4f4c78bf1895378f376815910812daf79a216f"
dependencies: dependencies:
ansi-html "0.0.7" ansi-html "0.0.7"
array-includes "^3.0.3" array-includes "^3.0.3"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment