Skip to content

Commit ef1ae2b

Browse files
committed
optimize webpack workflow
1 parent 6f496ac commit ef1ae2b

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "dist/APlayer.min.js",
66
"scripts": {
77
"test": "webpack",
8-
"start": "webpack-dev-server --hot --progress --inline --host 0.0.0.0"
8+
"build": "webpack",
9+
"dev": "WEBPACK_ENV=dev webpack-dev-server --hot --progress --inline --host 0.0.0.0"
910
},
1011
"repository": {
1112
"type": "git",

webpack.config.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@ var webpack = require('webpack');
22
var path = require('path');
33
var autoprefixer = require('autoprefixer');
44

5+
var libraryName = 'APlayer';
6+
var env = process.env.WEBPACK_ENV;
57
var ROOT_PATH = path.resolve(__dirname);
68
var APP_PATH = path.resolve(ROOT_PATH, 'src');
79
var BUILD_PATH = path.resolve(ROOT_PATH, 'dist');
810

9-
module.exports = {
10-
devtool: 'source-map',
11+
var plugins = [];
12+
if (env !== 'dev') {
13+
plugins.push(
14+
new webpack.optimize.UglifyJsPlugin({
15+
compress: {
16+
warnings: false
17+
},
18+
minimize: true
19+
})
20+
);
21+
}
1122

12-
entry: './src/APlayer.js',
23+
module.exports = {
24+
entry: './src/' + libraryName + '.js',
1325

1426
output: {
1527
path: BUILD_PATH,
16-
filename: 'APlayer.min.js',
17-
library: 'APlayer',
28+
filename: libraryName + '.min.js',
29+
library: libraryName,
1830
libraryTarget: 'umd',
1931
umdNamedDefine: true
2032
},
2133

34+
devtool: 'source-map',
35+
2236
devServer: {
2337
publicPath: "/dist/",
2438
},
@@ -45,13 +59,7 @@ module.exports = {
4559
]
4660
},
4761

48-
plugins: [
49-
new webpack.optimize.UglifyJsPlugin({
50-
compress: {
51-
warnings: false
52-
}
53-
})
54-
],
62+
plugins: plugins,
5563

5664
postcss: [
5765
autoprefixer({

0 commit comments

Comments
 (0)