Fix browsersync (#1815)
* Update dependencies * Remove monkey-hot-loader * Use webpack-merge instead of util/mergeWithConcat() * Fix: copyglobs plugin `after-emit` is bound twice * NoErrorsPlugin() is deprecated in favor of NoEmitOnErrorsPlugin() * webpack-dev-middleware should use same publicPath as compiler * webpack-hot-middleware/client should be prepended to entries * Browser should refresh when HMR fails * Bootstrap package.json has correct main property Sometime between alpha 2 and 3, package.json was pointing to nonexistent file, so we referenced file manually in our repo. Underlying issue was fixed by alpha 4, so we no longer have to specify full path to file.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
const uniq = require('lodash/uniq');
|
const uniq = require('lodash/uniq');
|
||||||
|
const merge = require('webpack-merge');
|
||||||
|
|
||||||
const mergeWithConcat = require('./util/mergeWithConcat');
|
|
||||||
const userConfig = require('../config');
|
const userConfig = require('../config');
|
||||||
|
|
||||||
const isProduction = !!((argv.env && argv.env.production) || argv.p);
|
const isProduction = !!((argv.env && argv.env.production) || argv.p);
|
||||||
@@ -10,7 +10,7 @@ const rootPath = (userConfig.paths && userConfig.paths.root)
|
|||||||
? userConfig.paths.root
|
? userConfig.paths.root
|
||||||
: process.cwd();
|
: process.cwd();
|
||||||
|
|
||||||
const config = mergeWithConcat({
|
const config = merge({
|
||||||
copy: 'images/**/*',
|
copy: 'images/**/*',
|
||||||
proxyUrl: 'http://localhost:3000',
|
proxyUrl: 'http://localhost:3000',
|
||||||
cacheBusting: '[name]_[hash]',
|
cacheBusting: '[name]_[hash]',
|
||||||
@@ -32,7 +32,7 @@ const config = mergeWithConcat({
|
|||||||
config.watch.push(`${path.basename(config.paths.assets)}/${config.copy}`);
|
config.watch.push(`${path.basename(config.paths.assets)}/${config.copy}`);
|
||||||
config.watch = uniq(config.watch);
|
config.watch = uniq(config.watch);
|
||||||
|
|
||||||
module.exports = mergeWithConcat(config, {
|
module.exports = merge(config, {
|
||||||
env: Object.assign({ production: isProduction, development: !isProduction }, argv.env),
|
env: Object.assign({ production: isProduction, development: !isProduction }, argv.env),
|
||||||
publicPath: `${config.publicPath}/${path.basename(config.paths.dist)}/`,
|
publicPath: `${config.publicPath}/${path.basename(config.paths.dist)}/`,
|
||||||
manifest: {},
|
manifest: {},
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ module.exports = (entry) => {
|
|||||||
const results = {};
|
const results = {};
|
||||||
const hotMiddlewareScript = `webpack-hot-middleware/client?${qs.stringify({
|
const hotMiddlewareScript = `webpack-hot-middleware/client?${qs.stringify({
|
||||||
timeout: 20000,
|
timeout: 20000,
|
||||||
reload: false,
|
reload: true,
|
||||||
})}`;
|
})}`;
|
||||||
|
|
||||||
Object.keys(entry).forEach((name) => {
|
Object.keys(entry).forEach((name) => {
|
||||||
results[name] = Array.isArray(entry[name]) ? entry[name].slice(0) : [entry[name]];
|
results[name] = Array.isArray(entry[name]) ? entry[name].slice(0) : [entry[name]];
|
||||||
results[name].push(hotMiddlewareScript);
|
results[name].unshift(hotMiddlewareScript);
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
const mergeWith = require('lodash/mergeWith');
|
|
||||||
|
|
||||||
module.exports = function mergeWithConcat() {
|
|
||||||
const args = [].slice.call(arguments);
|
|
||||||
args.push((a, b) => {
|
|
||||||
if (Array.isArray(a) && Array.isArray(b)) {
|
|
||||||
return a.concat(b);
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
});
|
|
||||||
return mergeWith.apply(this, args);
|
|
||||||
};
|
|
||||||
@@ -2,30 +2,17 @@
|
|||||||
|
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const qs = require('qs');
|
const qs = require('qs');
|
||||||
|
const merge = require('webpack-merge');
|
||||||
const autoprefixer = require('autoprefixer');
|
const autoprefixer = require('autoprefixer');
|
||||||
const CleanPlugin = require('clean-webpack-plugin');
|
const CleanPlugin = require('clean-webpack-plugin');
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
|
||||||
const CopyGlobsPlugin = require('./webpack.plugin.copyglobs');
|
const CopyGlobsPlugin = require('./webpack.plugin.copyglobs');
|
||||||
const mergeWithConcat = require('./util/mergeWithConcat');
|
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
|
|
||||||
const assetsFilenames = (config.enabled.cacheBusting) ? config.cacheBusting : '[name]';
|
const assetsFilenames = (config.enabled.cacheBusting) ? config.cacheBusting : '[name]';
|
||||||
const sourceMapQueryStr = (config.enabled.sourceMaps) ? '+sourceMap' : '-sourceMap';
|
const sourceMapQueryStr = (config.enabled.sourceMaps) ? '+sourceMap' : '-sourceMap';
|
||||||
|
|
||||||
const jsLoader = {
|
|
||||||
test: /\.js$/,
|
|
||||||
exclude: [/(node_modules|bower_components)(?)/],
|
|
||||||
use: [{
|
|
||||||
loader: 'buble',
|
|
||||||
options: { objectAssign: 'Object.assign' },
|
|
||||||
}],
|
|
||||||
};
|
|
||||||
|
|
||||||
if (config.enabled.watcher) {
|
|
||||||
jsLoader.use.unshift('monkey-hot?sourceType=module');
|
|
||||||
}
|
|
||||||
|
|
||||||
let webpackConfig = {
|
let webpackConfig = {
|
||||||
context: config.paths.assets,
|
context: config.paths.assets,
|
||||||
entry: config.entry,
|
entry: config.entry,
|
||||||
@@ -37,13 +24,18 @@ let webpackConfig = {
|
|||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
jsLoader,
|
|
||||||
{
|
{
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
test: /\.js?$/,
|
test: /\.js?$/,
|
||||||
include: config.paths.assets,
|
include: config.paths.assets,
|
||||||
loader: 'eslint',
|
loader: 'eslint',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
exclude: [/(node_modules|bower_components)(?)/],
|
||||||
|
loader: 'buble',
|
||||||
|
options: { objectAssign: 'Object.assign' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
include: config.paths.assets,
|
include: config.paths.assets,
|
||||||
@@ -171,11 +163,11 @@ let webpackConfig = {
|
|||||||
/* eslint-disable global-require */ /** Let's only load dependencies as needed */
|
/* eslint-disable global-require */ /** Let's only load dependencies as needed */
|
||||||
|
|
||||||
if (config.enabled.optimize) {
|
if (config.enabled.optimize) {
|
||||||
webpackConfig = mergeWithConcat(webpackConfig, require('./webpack.config.optimize'));
|
webpackConfig = merge(webpackConfig, require('./webpack.config.optimize'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.env.production) {
|
if (config.env.production) {
|
||||||
webpackConfig.plugins.push(new webpack.NoErrorsPlugin());
|
webpackConfig.plugins.push(new webpack.NoEmitOnErrorsPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.enabled.cacheBusting) {
|
if (config.enabled.cacheBusting) {
|
||||||
@@ -194,7 +186,7 @@ if (config.enabled.cacheBusting) {
|
|||||||
|
|
||||||
if (config.enabled.watcher) {
|
if (config.enabled.watcher) {
|
||||||
webpackConfig.entry = require('./util/addHotMiddleware')(webpackConfig.entry);
|
webpackConfig.entry = require('./util/addHotMiddleware')(webpackConfig.entry);
|
||||||
webpackConfig = mergeWithConcat(webpackConfig, require('./webpack.config.watch'));
|
webpackConfig = merge(webpackConfig, require('./webpack.config.watch'));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = webpackConfig;
|
module.exports = webpackConfig;
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ module.exports = {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.OccurrenceOrderPlugin(),
|
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
new webpack.NoErrorsPlugin(),
|
new webpack.NoEmitOnErrorsPlugin(),
|
||||||
new BrowserSyncPlugin({
|
new BrowserSyncPlugin({
|
||||||
target: config.devUrl,
|
target: config.devUrl,
|
||||||
publicPath: config.publicPath,
|
|
||||||
proxyUrl: config.proxyUrl,
|
proxyUrl: config.proxyUrl,
|
||||||
watch: config.watch,
|
watch: config.watch,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ module.exports = class {
|
|||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
compiler.plugin('emit', this.emitHandler.bind(this));
|
compiler.plugin('emit', this.emitHandler.bind(this));
|
||||||
compiler.plugin('after-emit', this.afterEmitHandler.bind(this));
|
compiler.plugin('after-emit', this.afterEmitHandler.bind(this));
|
||||||
compiler.plugin('after-emit', this.afterEmitHandler.bind(this));
|
|
||||||
this.started = true;
|
this.started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/** import external dependencies */
|
/** import external dependencies */
|
||||||
import 'jquery';
|
import 'jquery';
|
||||||
import 'bootstrap/dist/js/bootstrap';
|
import 'bootstrap';
|
||||||
|
|
||||||
/** import local dependencies */
|
/** import local dependencies */
|
||||||
import Router from './util/Router';
|
import Router from './util/Router';
|
||||||
|
|||||||
18
package.json
18
package.json
@@ -31,9 +31,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^6.6.1",
|
"autoprefixer": "^6.6.1",
|
||||||
"body-parser": "^1.15.2",
|
"body-parser": "^1.16.0",
|
||||||
"browser-sync": "^2.18.6",
|
"browser-sync": "^2.18.6",
|
||||||
"browsersync-webpack-plugin": "^0.2.0",
|
"browsersync-webpack-plugin": "^0.3.3",
|
||||||
"buble": "^0.15.2",
|
"buble": "^0.15.2",
|
||||||
"buble-loader": "^0.4.0",
|
"buble-loader": "^0.4.0",
|
||||||
"clean-webpack-plugin": "^0.1.15",
|
"clean-webpack-plugin": "^0.1.15",
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
"cssnano": "^3.10.0",
|
"cssnano": "^3.10.0",
|
||||||
"eslint": "^3.13.1",
|
"eslint": "^3.13.1",
|
||||||
"eslint-loader": "^1.6.1",
|
"eslint-loader": "^1.6.1",
|
||||||
"eslint-plugin-import": "^2.0.1",
|
"eslint-plugin-import": "^2.2.0",
|
||||||
"extract-text-webpack-plugin": "^2.0.0-beta.4",
|
"extract-text-webpack-plugin": "^2.0.0-beta.4",
|
||||||
"file-loader": "^0.9.0",
|
"file-loader": "^0.9.0",
|
||||||
"glob": "^7.1.1",
|
"glob": "^7.1.1",
|
||||||
@@ -51,21 +51,21 @@
|
|||||||
"loader-utils": "^0.2.16",
|
"loader-utils": "^0.2.16",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
"monkey-hot-loader": "github:rmarscher/monkey-hot-loader#webpack2-import",
|
"node-sass": "^4.3.0",
|
||||||
"node-sass": "^4.2.0",
|
|
||||||
"optimize-css-assets-webpack-plugin": "^1.3.0",
|
"optimize-css-assets-webpack-plugin": "^1.3.0",
|
||||||
"postcss": "^5.2.9",
|
"postcss": "^5.2.10",
|
||||||
"postcss-loader": "^1.2.1",
|
"postcss-loader": "^1.2.2",
|
||||||
"qs": "^6.3.0",
|
"qs": "^6.3.0",
|
||||||
"resolve-url-loader": "^1.6.1",
|
"resolve-url-loader": "^1.6.1",
|
||||||
"rimraf": "^2.5.4",
|
"rimraf": "^2.5.4",
|
||||||
"sass-loader": "^4.1.1",
|
"sass-loader": "^4.1.1",
|
||||||
"style-loader": "^0.13.1",
|
"style-loader": "^0.13.1",
|
||||||
"url-loader": "^0.5.7",
|
"url-loader": "^0.5.7",
|
||||||
"webpack": "^2.2.0-rc.3",
|
"webpack": "^2.2.0",
|
||||||
"webpack-assets-manifest": "^0.6.1",
|
"webpack-assets-manifest": "^0.6.1",
|
||||||
"webpack-dev-middleware": "^1.9.0",
|
"webpack-dev-middleware": "^1.9.0",
|
||||||
"webpack-hot-middleware": "^2.15.0"
|
"webpack-hot-middleware": "^2.15.0",
|
||||||
|
"webpack-merge": "^2.4.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bootstrap": "^4.0.0-alpha.6",
|
"bootstrap": "^4.0.0-alpha.6",
|
||||||
|
|||||||
Reference in New Issue
Block a user