Skip to content

Commit 3d0b7d7

Browse files
committed
minify when building for production
1 parent d547255 commit 3d0b7d7

2 files changed

Lines changed: 42 additions & 36 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"examples/"
2020
],
2121
"scripts": {
22-
"build": "webpack -p",
23-
"prepublishOnly": "npm run build",
22+
"buildProduction": "webpack --env production",
23+
"prepublishOnly": "npm run buildProduction",
2424
"lint": "tslint -c tslint.json 'src/**/*.ts'"
2525
},
2626
"dependencies": {

webpack.config.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
const path = require('path')
2+
const MinifyPlugin = require("babel-minify-webpack-plugin");
23

3-
module.exports = {
4-
entry: './src/index.ts',
5-
module: {
6-
rules: [
7-
{
8-
test: /\.tsx?$/,
9-
loader: 'ts-loader',
10-
exclude: /node_modules/
11-
},
12-
{
13-
test: /\.css$/,
14-
use: [
15-
{
16-
loader: 'style-loader'
17-
},
18-
{
19-
loader: 'css-loader',
20-
options: {
21-
modules: true,
4+
module.exports = (env) => {
5+
let plugins = []
6+
if (env === 'production')
7+
plugins = [new MinifyPlugin()];
8+
9+
return {
10+
entry: './src/index.ts',
11+
module: {
12+
rules: [
13+
{
14+
test: /\.tsx?$/,
15+
loader: 'ts-loader',
16+
exclude: /node_modules/
17+
},
18+
{
19+
test: /\.css$/,
20+
use: [
21+
{
22+
loader: 'style-loader'
23+
},
24+
{
25+
loader: 'css-loader',
26+
options: {
27+
modules: true,
28+
}
2229
}
23-
}
24-
]
25-
}
26-
]
27-
},
28-
resolve: {
29-
extensions: [ ".ts", ".js" ]
30-
},
31-
output: {
32-
filename: 'index.js',
33-
path: path.resolve(__dirname, 'dist'),
34-
libraryTarget: "umd"
35-
},
36-
plugins: [
37-
]
30+
]
31+
}
32+
]
33+
},
34+
resolve: {
35+
extensions: [ ".ts", ".js" ]
36+
},
37+
output: {
38+
filename: 'index.js',
39+
path: path.resolve(__dirname, 'dist'),
40+
libraryTarget: "umd"
41+
},
42+
plugins
43+
}
3844
};

0 commit comments

Comments
 (0)