Skip to content

Commit

Permalink
build(): update to webpack 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Mar 7, 2018
1 parent 184de26 commit 897c562
Show file tree
Hide file tree
Showing 4 changed files with 3,828 additions and 1,033 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,6 +7,7 @@ awsconfig
/public_gen
/tmp
/build
/.cache-loader
vendor/phantomjs/phantomjs

docs/AWS_S3_BUCKET
Expand Down
62 changes: 33 additions & 29 deletions package.json
Expand Up @@ -17,47 +17,50 @@
"url": "https://github.com/OpenNMS/opennms-js.git"
},
"devDependencies": {
"@types/jest": "^19.2.3",
"@types/node": "^7.0.18",
"@types/urijs": "^1.15.32",
"babel-cli": "^6.24.1",
"babel-jest": "^20.0.3",
"babel-loader": "^7.0.0",
"@types/jest": "^22.2.0",
"@types/lodash": "^4.14.104",
"@types/node": "^9.4.6",
"@types/urijs": "^1.15.36",
"babel-cli": "^6.26.0",
"babel-jest": "^22.4.1",
"babel-loader": "^7.1.4",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-for-of": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-regenerator": "^6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.5.1",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"chai": "3.5.0",
"chai": "^4.1.2",
"child_process": "^1.0.2",
"conventional-changelog-lint": "^1.1.9",
"husky": "^0.13.3",
"jest": "^20.0.3",
"conventional-changelog-lint": "^2.1.1",
"husky": "^0.14.3",
"jest": "^22.4.2",
"jest-environment-node-debug": "^2.0.0",
"lodash.clonedeep": "^4.5.0",
"parallel-webpack": "^2.0.0",
"regenerator-runtime": "^0.10.5",
"standard-changelog": "^1.0.1",
"ts-jest": "^20.0.4",
"ts-loader": "^2.0.3",
"ts-node": "^3.0.4",
"tslint": "^5.2.0",
"tslint-loader": "^3.5.3",
"typedoc": "^0.7.1",
"typedoc-plugin-external-module-name": "^1.0.9",
"parallel-webpack": "^2.3.0",
"regenerator-runtime": "^0.11.1",
"standard-changelog": "^1.0.13",
"ts-jest": "^22.4.1",
"ts-loader": "^4.0.1",
"ts-node": "^5.0.1",
"tslint": "^5.9.1",
"tslint-loader": "https://github.com/wbuchwalter/tslint-loader.git#093230076f3b453c4f8b7aa2ee074932aa109e84",
"typedoc": "^0.11.0",
"typedoc-plugin-external-module-name": "^1.1.1",
"typedoc-webpack-plugin": "^1.1.4",
"typescript": "2.x",
"urijs": "^1.17.1",
"webpack": "^2.5.1",
"webpack-closure-compiler": "^2.1.4",
"yargs": "^8.0.1"
"uglifyjs-webpack-plugin": "^1.2.2",
"urijs": "^1.19.1",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.10",
"webpack-closure-compiler": "^2.1.6",
"yargs": "^11.0.0"
},
"jest": {
"verbose": true,
Expand All @@ -74,6 +77,7 @@
},
"dependencies": {
"axios": "^0.16.1",
"cache-loader": "^1.2.2",
"cli-table": "^0.3.1",
"commander": "^2.9.0",
"fs": "^0.0.1-security",
Expand Down
65 changes: 45 additions & 20 deletions webpack.config.js
@@ -1,6 +1,7 @@
var webpack = require('webpack');
var path = require('path');
var TypedocWebpackPlugin = require('typedoc-webpack-plugin');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var pkginfo = require('./package.json');

var createVariants = require('parallel-webpack').createVariants;
Expand Down Expand Up @@ -40,26 +41,17 @@ var config = {
},
module: {
rules: [
{
enforce: 'pre',
test: /\.tsx?$/,
use: [
{
loader: 'tslint-loader',
options: {
typeCheck: true
}
}
],
exclude: [/node_modules/],
},
{
test: /(\.jsx?)$/,
use: [ 'babel-loader' ]
use: [
'cache-loader',
'babel-loader'
]
},
{
test: /(\.tsx?)$/,
use: [
'cache-loader',
'babel-loader',
'ts-loader'
],
Expand Down Expand Up @@ -93,6 +85,8 @@ function createConfig(options) {
'global.OPENNMS_JS_VERSION': JSON.stringify(pkginfo.version),
};

myconf.mode = options.production? 'production':'development';

if (options.target === 'web') {
myconf.target = 'web';
} else {
Expand All @@ -111,19 +105,50 @@ function createConfig(options) {
}));
}

if (!myconf.optimization) {
myconf.optimization = {};
}

if (options.production) {
myconf.optimization.minimize = true;
if (!myconf.optimization.minimizer) {
myconf.optimization.minimizer = [];
} else {
console.log('minimizer exists:',myconf.optimization.minimizer);
}
myconf.optimization.minimizer.push(new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: {
mangle: {
reserved: [ '$element', '$super', '$scope', '$uib', '$', 'jQuery', 'exports', 'require', 'angular', 'c3', 'd3' ]
},
compress: true
}
}));

myconf.module.rules.unshift({
// run tslint on typescript files before rendering
enforce: 'pre',
test: /\.tsx?$/,
use: [
{
loader: 'tslint-loader',
options: {
typeCheck: true
}
}
],
exclude: [/node_modules/]
});

defs['global.GENTLY'] = false;

myconf.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}));
myconf.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
mangle: true,
minimize: true,
compress: true,
}));
myconf.output.filename += '.min';
}

Expand Down

0 comments on commit 897c562

Please sign in to comment.