Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to webpack v3. #854

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions external.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var path = require('path');
var webpack = require('webpack');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
/* webpack 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be "webpack 3" - assuming this was left over

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some preliminary work to use webpack 4 that is commented out. I can remove it, but wanted to preserve it in some commit for when we move to webpack 4. Unfortunately, karma-webpack is not webpack 4 compatible yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is fine. I was just making sure.

mode: 'production',
*/
performance: {hints: false},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It suppresses certain warning messages. Webpack, for instance, complains that the proj4 inclusion is large and could be broken into smaller modules, but we want proj4 as it stands, so this is not a useful warning. Rather than see this on every build, this turns those warnings off.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

cache: true,
context: path.join(__dirname, 'src'),
entry: {
'geo.ext': './vendor.js',
Expand All @@ -18,18 +23,41 @@ module.exports = {
hammerjs: 'hammerjs/hammer.js'
}
},
/* webpack 3 */
plugins: [
new webpack.optimize.UglifyJsPlugin({
new UglifyJsPlugin({
include: /\.min\.js$/,
minimize: true,
comments: /@(license|copyright)/
parallel: true,
uglifyOptions: {
compress: true,
comments: /@(license|copyright)/
},
sourceMap: true
})
],
/* end webpack 3 */
/* webpack 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we keeping commented code for the future work?

optimization: {
minimizer: [
new UglifyJsPlugin({
include: /\.min\.js$/,
parallel: true,
uglifyOptions: {
compress: true,
comments: /@(license|copyright)/
},
sourceMap: true
})
]
},
*/
module: {
loaders: [{
test: require.resolve('d3'), loader: 'expose?d3'
rules: [{
test: require.resolve('d3'),
use: ['expose-loader?d3']
}, {
test: require.resolve('hammerjs'), loader: 'expose?hammerjs'
test: require.resolve('hammerjs'),
use: ['expose-loader?hammerjs']
}]
}
};
30 changes: 26 additions & 4 deletions karma-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ var FirefoxPrefs = {
};

module.exports = function (config) {
webpack_config.plugins.push(function () {
this.plugin('done', function (stats) {
if (stats.compilation.warnings.length) {
// Log each of the warnings
stats.compilation.warnings.forEach(function (warning) {
console.log(warning.message || warning);
});
// Pretend no assets were generated. This prevents the tests
// from running making it clear that there were warnings.
stats.stats = [{
toJson: function () {
return this;
},
assets: []
}];
}
});
});
var newConfig = {
autoWatch: false,
files: [
Expand Down Expand Up @@ -300,7 +318,7 @@ module.exports = function (config) {
'--kiosk',
'--incognito',
'--translate-script-url=""',
'--proxy-pac-url=' + config.protocol + '//' + config.hostname + ':' + config.port + '/testdata/proxy-for-tests.pac'
'--proxy-pac-url=' + config.protocol + '//' + (config.hostname || '127.0.0.1') + ':' + config.port + '/testdata/proxy-for-tests.pac'
])
},
FirefoxHeadlessTouch: {
Expand All @@ -315,7 +333,7 @@ module.exports = function (config) {
prefs: Object.assign({
// enable proxy
'network.proxy.type': 2,
'network.proxy.autoconfig_url': config.protocol + '//' + config.hostname + ':' + config.port + '/testdata/proxy-for-tests.pac',
'network.proxy.autoconfig_url': config.protocol + '//' + (config.hostname || '127.0.0.1') + ':' + config.port + '/testdata/proxy-for-tests.pac',
// enable touch
'dom.w3c_touch_events.enabled': 1
}, FirefoxPrefs)
Expand Down Expand Up @@ -347,13 +365,17 @@ module.exports = function (config) {
}
},
webpack: {
/* webpack 4
mode: 'production',
*/
performance: {hints: false},
cache: true,
devtool: 'inline-source-map',
module: {
loaders: webpack_config.module.loaders
rules: webpack_config.module.rules
},
resolve: webpack_config.resolve,
plugins: webpack_config.exposed_plugins
plugins: webpack_config.plugins
},
webpackMiddleware: {
stats: 'errors-only'
Expand Down
12 changes: 5 additions & 7 deletions karma-cov.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ module.exports = function (config) {
{type: 'text'}
]
};
karma_config.webpack.module.preLoaders = [
{
test: /\.js$/,
include: path.resolve('src/'),
loader: 'istanbul-instrumenter'
}
];
karma_config.webpack.module.rules.unshift({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between preloaders vs unshift?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like API change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unshift just adds to the beginning of an array. There are no longer preloaders in webpack 3; you just need to order your loaders correctly. This places the loader first.

test: /\.js$/,
include: path.resolve('src/'),
use: ['istanbul-instrumenter-loader']
});

config.set(karma_config);
};
Loading