Browse Source

optimize webpack workflow

DIYgod 8 years ago
parent
commit
1e4786c3fb
3 changed files with 25 additions and 17 deletions
  1. 2 2
      README.md
  2. 2 1
      package.json
  3. 21 14
      webpack.config.js

+ 2 - 2
README.md

@@ -41,14 +41,14 @@ See [docs](http://dplayer.js.org/docs)
 
 ```
 $ npm install
-$ npm run start
+$ npm run dev
 ```
 
 ## Make a release
 
 ```
 $ npm install
-$ npm run test
+$ npm run build
 ```
 
 ## Related Projects

+ 2 - 1
package.json

@@ -5,7 +5,8 @@
   "main": "dist/DPlayer.min.js",
   "scripts": {
     "test": "webpack",
-    "start": "webpack-dev-server --hot --progress --inline --host 0.0.0.0"
+    "build": "webpack",
+    "dev": "WEBPACK_ENV=dev webpack-dev-server --hot --progress --inline --host 0.0.0.0"
   },
   "repository": {
     "type": "git",

+ 21 - 14
webpack.config.js

@@ -2,29 +2,42 @@ var webpack = require('webpack');
 var path = require('path');
 var autoprefixer = require('autoprefixer');
 
+var libraryName = 'DPlayer';
+var env = process.env.WEBPACK_ENV;
 var ROOT_PATH = path.resolve(__dirname);
 var APP_PATH = path.resolve(ROOT_PATH, 'src');
 var BUILD_PATH = path.resolve(ROOT_PATH, 'dist');
 
-module.exports = {
-    devtool: 'source-map',
+var plugins = [];
+if (env !== 'dev') {
+    plugins.push(
+        new webpack.optimize.UglifyJsPlugin({
+            compress: {
+                warnings: false
+            },
+            minimize: true
+        })
+    );
+}
 
-    entry: './src/DPlayer.js',
+module.exports = {
+    entry: './src/' + libraryName + '.js',
 
     output: {
         path: BUILD_PATH,
-        filename: 'DPlayer.min.js',
-        library: 'DPlayer',
+        filename: libraryName + '.min.js',
+        library: libraryName,
         libraryTarget: 'umd',
         umdNamedDefine: true
     },
 
+    devtool: 'source-map',
+
     devServer: {
-        publicPath: "/dist/"
+        publicPath: "/dist/",
     },
 
     module: {
-        // noParse: /node_modules\/hls.js\/dist\/hls.js/,
         loaders: [
             {
                 test: /\.js$/,
@@ -46,13 +59,7 @@ module.exports = {
         ]
     },
 
-    plugins: [
-        new webpack.optimize.UglifyJsPlugin({
-            compress: {
-                warnings: false
-            }
-        })
-    ],
+    plugins: plugins,
 
     postcss: [
         autoprefixer({