Переглянути джерело

Added package which will clean up old dist files after every compile

howdoyoucode 8 роки тому
батько
коміт
6ad5787835
3 змінених файлів з 127 додано та 95 видалено
  1. 33 8
      frontend/package-lock.json
  2. 1 0
      frontend/package.json
  3. 93 87
      frontend/webpack.config.js

+ 33 - 8
frontend/package-lock.json

@@ -693,8 +693,7 @@
     },
     "balanced-match": {
       "version": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.2.tgz",
-      "integrity": "sha1-yz8+PHMtwPAe5wtAPzAuYddwmDg=",
-      "dev": true
+      "integrity": "sha1-yz8+PHMtwPAe5wtAPzAuYddwmDg="
     },
     "base16": {
       "version": "https://registry.npmjs.org/base16/-/base16-1.0.0.tgz",
@@ -779,8 +778,7 @@
     },
     "brace-expansion": {
       "version": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.7.tgz",
-      "integrity": "sha1-Pv/DxQ4ABTH7cg6v+A8K6O8jz1k=",
-      "dev": true
+      "integrity": "sha1-Pv/DxQ4ABTH7cg6v+A8K6O8jz1k="
     },
     "braces": {
       "version": "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz",
@@ -934,6 +932,20 @@
         }
       }
     },
+    "clean-webpack-plugin": {
+      "version": "0.1.16",
+      "resolved": "https://registry.npmjs.org/clean-webpack-plugin/-/clean-webpack-plugin-0.1.16.tgz",
+      "integrity": "sha1-QiqOFQvz1av9PRS/rLBw6A+y4j8=",
+      "dev": true,
+      "dependencies": {
+        "rimraf": {
+          "version": "2.5.4",
+          "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.5.4.tgz",
+          "integrity": "sha1-loAAk8vxoMhr2VtGJUZ1NcKd+gQ=",
+          "dev": true
+        }
+      }
+    },
     "cli-cursor": {
       "version": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz",
       "integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=",
@@ -1042,8 +1054,7 @@
     },
     "concat-map": {
       "version": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
-      "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
-      "dev": true
+      "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
     },
     "concat-stream": {
       "version": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz",
@@ -3220,6 +3231,11 @@
       "integrity": "sha1-h79AKSuM+D5OjOGjrkIJ4gBxZ1o=",
       "dev": true
     },
+    "lodash.union": {
+      "version": "4.6.0",
+      "resolved": "https://registry.npmjs.org/lodash.union/-/lodash.union-4.6.0.tgz",
+      "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg="
+    },
     "longest": {
       "version": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
       "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=",
@@ -3316,8 +3332,7 @@
     },
     "minimatch": {
       "version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.3.tgz",
-      "integrity": "sha1-Kk5AkLlrLbBqnX3wEFWmKnfJt3Q=",
-      "dev": true
+      "integrity": "sha1-Kk5AkLlrLbBqnX3wEFWmKnfJt3Q="
     },
     "minimist": {
       "version": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
@@ -3980,6 +3995,11 @@
       "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
       "dev": true
     },
+    "recursive-readdir-sync": {
+      "version": "1.0.6",
+      "resolved": "https://registry.npmjs.org/recursive-readdir-sync/-/recursive-readdir-sync-1.0.6.tgz",
+      "integrity": "sha1-Hb9tMvPFu4083pemxYjVR6nhPVY="
+    },
     "redbox-react": {
       "version": "https://registry.npmjs.org/redbox-react/-/redbox-react-1.3.6.tgz",
       "integrity": "sha1-cDFMV8BmJX63Cwok3HlLXO9PHE4=",
@@ -4906,6 +4926,11 @@
         }
       }
     },
+    "webpack-cleanup-plugin": {
+      "version": "0.5.1",
+      "resolved": "https://registry.npmjs.org/webpack-cleanup-plugin/-/webpack-cleanup-plugin-0.5.1.tgz",
+      "integrity": "sha1-3y1wa9dTZMBuZbBRGGMW1nTrlq8="
+    },
     "webpack-dashboard": {
       "version": "https://registry.npmjs.org/webpack-dashboard/-/webpack-dashboard-0.2.1.tgz",
       "integrity": "sha1-h+G+UP8FXQVbeWosVDgfMq8vVbk=",

+ 1 - 0
frontend/package.json

@@ -24,6 +24,7 @@
     "babel-preset-react-hmre": "^1.1.1",
     "babel-preset-stage-0": "^6.16.0",
     "babel-runtime": "^6.6.1",
+    "clean-webpack-plugin": "^0.1.16",
     "css-loader": "0.14.5",
     "eslint": "^3.10.1",
     "eslint-config-airbnb": "^13.0.0",

+ 93 - 87
frontend/webpack.config.js

@@ -1,6 +1,7 @@
 const webpack = require("webpack");
 const path = require("path");
 
+const CleanupPlugin = require("clean-webpack-plugin");
 const HtmlWebpackPlugin = require("html-webpack-plugin");
 const ExtractTextPlugin = require("extract-text-webpack-plugin");
 const autoprefixer = require("autoprefixer");
@@ -23,67 +24,72 @@ const plugins = [
 	new webpack.optimize.OccurrenceOrderPlugin(),
 	new webpack.HotModuleReplacementPlugin(),
 	new webpack.NoEmitOnErrorsPlugin(),
-  new webpack.DefinePlugin({
-    "process.env": {
+	new webpack.DefinePlugin({
+		"process.env": {
 			NODE_ENV: JSON.stringify(nodeEnv),
-    },
-  }),
-  new webpack.NamedModulesPlugin(),
-  new webpack.LoaderOptionsPlugin({
-    options: {
-      postcss: [
-        autoprefixer({
-          browsers: [
-            "last 3 version",
-            "ie >= 10",
-          ],
-        }),
-      ],
-      context: path.join(__dirname, "./app"),
-    },
-  }),
+		},
+	}),
+	new webpack.NamedModulesPlugin(),
+	new CleanupPlugin(["dist"], {
+		verbose: true,
+		dry: true,
+		watch: true,
+	}),
+	new webpack.LoaderOptionsPlugin({
+		options: {
+			postcss: [
+				autoprefixer({
+					browsers: [
+						"last 3 version",
+						"ie >= 10",
+					],
+				}),
+			],
+			context: path.join(__dirname, "./app"),
+		},
+	}),
 ];
 
 const rules = [
-  {
-    test: /\.(js|jsx)$/,
-    exclude: /node_modules/,
-    use: [
-      "babel-loader",
-    ],
-  },
-  {
-    test: /\.(png|gif|jpg|svg)$/,
-    include: path.join(__dirname, "./app/assets/images"),
-    use: "url-loader?limit=20480&name=assets/[name]-[hash].[ext]",
-  },
+	{
+		test: /\.(js|jsx)$/,
+		exclude: /node_modules/,
+		use: [
+			"babel-loader",
+		],
+	},
+	{
+		test: /\.(png|gif|jpg|svg)$/,
+		include: path.join(__dirname, "./app/assets/images"),
+		use: "url-loader?limit=20480&name=assets/[name]-[hash].[ext]",
+	},
 ];
 
 if (nodeEnv === "production") {
-  plugins.push(
-    new webpack.LoaderOptionsPlugin({
-      minimize: true,
-      debug: false,
-    }),
-    new webpack.optimize.UglifyJsPlugin({
-      compress: {
-        warnings: false,
-        screw_ie8: true,
-        conditionals: true,
-        unused: true,
-        comparisons: true,
-        sequences: true,
-        dead_code: true,
-        evaluate: true,
-        if_return: true,
-        join_vars: true,
-      },
-      output: {
-        comments: false,
-      },
-    }),
-    new ExtractTextPlugin("style-[hash].css")
-  );
+	plugins.push(
+		new webpack.LoaderOptionsPlugin({
+			minimize: true,
+			debug: false,
+		}),
+		new webpack.optimize.UglifyJsPlugin({
+			compress: {
+				warnings: false,
+				screw_ie8: true,
+				conditionals: true,
+				unused: true,
+				comparisons: true,
+				sequences: true,
+				dead_code: true,
+				evaluate: true,
+				if_return: true,
+				join_vars: true,
+			},
+			output: {
+				comments: false,
+			},
+		}),
+		new ExtractTextPlugin("style-[hash].css")
+	);
 
   rules.push({
 		test: /\.scss$/,
@@ -107,37 +113,37 @@ if (nodeEnv === "production") {
 }
 
 module.exports = {
-  devtool: nodeEnv === "production" ? "eval" : "source-map",
-  context: path.join(__dirname, "./app"),
-  entry: {
-    app: "./js/index.js",
-    vendor: [
-      "babel-polyfill",
-      "es6-promise",
-      "immutable",
-      "isomorphic-fetch",
-      "react-dom",
-      "react-redux",
-      "react-router",
-      "react",
-      "redux-thunk",
-      "redux",
-    ],
-  },
-  output: {
-    path: path.join(__dirname, "./dist"),
-    publicPath: "/",
-    filename: "[name]-[hash].js",
-  },
-  module: {
-    rules,
-  },
-  resolve: {
-    extensions: [".webpack-loader.js", ".web-loader.js", ".loader.js", ".js", ".jsx"],
-    modules: [
-      path.resolve(__dirname, "node_modules"),
-      path.join(__dirname, "./app/js"),
-    ],
-  },
-  plugins
+	devtool: nodeEnv === "production" ? "eval" : "source-map",
+	context: path.join(__dirname, "./app"),
+	entry: {
+		app: "./js/index.js",
+		vendor: [
+			"babel-polyfill",
+			"es6-promise",
+			"immutable",
+			"isomorphic-fetch",
+			"react-dom",
+			"react-redux",
+			"react-router",
+			"react",
+			"redux-thunk",
+			"redux",
+		],
+	},
+	output: {
+		path: path.join(__dirname, "./dist"),
+		publicPath: "/",
+		filename: "[name]-[hash].js",
+	},
+	module: {
+		rules,
+	},
+	resolve: {
+		extensions: [".webpack-loader.js", ".web-loader.js", ".loader.js", ".js", ".jsx"],
+		modules: [
+			path.resolve(__dirname, "node_modules"),
+			path.join(__dirname, "./app/js"),
+		],
+	},
+	plugins
 };