Prevent webpack from rebooting while switching branches
This commit is contained in:
parent
566dc70b50
commit
c3564cd79e
3 changed files with 56 additions and 29 deletions
|
@ -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 generateAutoEntries(path, prefix = '.') {
|
function generateEntries() {
|
||||||
const chunkPath = path.replace(/\/index\.js$/, '');
|
// generate automatic entry points
|
||||||
const chunkName = chunkPath.replace(/\//g, '.');
|
var autoEntries = {};
|
||||||
autoEntries[chunkName] = `${prefix}/${path}`;
|
var pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') });
|
||||||
}
|
watchAutoEntries = [
|
||||||
|
path.join(ROOT_PATH, 'app/assets/javascripts/pages/'),
|
||||||
|
];
|
||||||
|
|
||||||
pageEntries.forEach(( path ) => generateAutoEntries(path));
|
function generateAutoEntries(path, prefix = '.') {
|
||||||
|
const chunkPath = path.replace(/\/index\.js$/, '');
|
||||||
|
const chunkName = chunkPath.replace(/\//g, '.');
|
||||||
|
autoEntries[chunkName] = `${prefix}/${path}`;
|
||||||
|
}
|
||||||
|
|
||||||
// report our auto-generated bundle count
|
pageEntries.forEach(( path ) => generateAutoEntries(path));
|
||||||
var autoEntriesCount = Object.keys(autoEntries).length;
|
|
||||||
console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`);
|
|
||||||
|
|
||||||
var config = {
|
autoEntriesCount = Object.keys(autoEntries).length;
|
||||||
// because sqljs requires fs.
|
|
||||||
node: {
|
const manualEntries = {
|
||||||
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 = {
|
||||||
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 = {
|
||||||
'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) {
|
||||||
};
|
};
|
||||||
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());
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"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 @@
|
||||||
"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:
|
||||||
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"
|
||||||
|
|
Loading…
Reference in a new issue