Skip to content

Commit fe9e76a

Browse files
committed
migrate to webpack 4
1 parent 4773800 commit fe9e76a

File tree

4 files changed

+1670
-53
lines changed

4 files changed

+1670
-53
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"autoformat": "prettier --config .prettierrc --write {src,test}/**/{*,*.test}.ts",
1111
"tslint-check": "tslint-config-prettier-check ./tslint.json",
1212
"clean-up": "rimraf .nyc_output && rimraf coverage && rimraf lib",
13+
"compile": "tsc -d",
14+
"dev": "webpack",
1315
"build": "webpack --env.production",
14-
"prepare": "npm run clean-up && tsc -d",
16+
"prepare": "npm run clean-up && npm run compile",
1517
"prepublishOnly": "publish-please guard",
1618
"publish-please": "npm run autoformat && npm run clean-up && npm run build && npm run test && publish-please"
1719
},
@@ -99,7 +101,9 @@
99101
"tslint": "^5.9.1",
100102
"tslint-config-prettier": "^1.9.0",
101103
"typescript": "^2.6.2",
104+
"uglifyjs-webpack-plugin": "^1.2.2",
102105
"webpack": "^4.1.0",
106+
"webpack-cli": "^2.0.10",
103107
"webpack-dev-server": "^3.1.0"
104108
}
105109
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"moduleResolution": "node",
88
"declaration": true,
99
"noImplicitAny": false,
10-
"sourceMap": true
10+
"sourceMap": false
1111
},
1212
"include": [
1313
"./src/**/*.ts"

webpack.config.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
const webpack = require('webpack');
22
const path = require('path');
3+
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
34

4-
module.exports = (function(options) {
5+
module.exports = (env => {
56

6-
if (!options) options = {isTest: false};
7+
if (!env) env = {production: false};
78

8-
var tsconfig = options.isTest ? "tsconfig.test.json" : "tsconfig.json";
9+
let tsconfig = env.production ? "tsconfig.json" : "tsconfig.test.json";
10+
let filename = env.production ? "signals.min.js" : "signals.js";
911

1012
return {
13+
mode: env.production ? "production" : "development",
1114
entry: {
1215
main: path.join(__dirname, "src/index.ts")
1316
},
1417

1518
output: {
1619
path: path.join(__dirname, "dist"),
17-
filename: "signals.min.js",
20+
filename: filename,
1821

1922
libraryTarget: "var",
2023
library: "SignalsJS"
2124
},
2225

23-
devtool: 'inline-source-map',
26+
devtool: env.production ? undefined : "inline-source-map",
2427

2528
module: {
2629
rules: [
27-
{ test: /\.ts$/, loader: "ts-loader?configFile=" + tsconfig },
2830
{
29-
test: ((options.production) /* disable this loader for production builds */
31+
test: /\.ts$/,
32+
loader: "ts-loader?configFile=" + tsconfig
33+
},
34+
{
35+
test: ((env.production) /* disable this loader for production builds */
3036
? /^$/
3137
: /^(.(?!\.test))*\.ts$/),
3238
loader: "istanbul-instrumenter-loader",
@@ -39,8 +45,8 @@ module.exports = (function(options) {
3945
},
4046

4147
plugins: (
42-
(options.production)
43-
? [ new webpack.optimize.UglifyJsPlugin({ sourceMap: false }) ]
48+
(env.production)
49+
? [ new UglifyJSPlugin() ]
4450
: [ new webpack.SourceMapDevToolPlugin({ test: /\.ts$/i }) ]
4551
),
4652

0 commit comments

Comments
 (0)