From e8705f0224be8531e93e2cf3b4032fb19e9d50f1 Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Mon, 19 Jun 2017 19:12:03 -0600 Subject: [PATCH] Used webpack-merge for webpack configs --- package.json | 3 ++- webpack/base.config.js | 33 +++++++++++++++++++++++++++++++++ webpack/dev.config.js | 23 ++++------------------- webpack/prod.config.js | 24 ++++-------------------- yarn.lock | 6 ++++++ 5 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 webpack/base.config.js diff --git a/package.json b/package.json index 96cdb64..a95d56c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "react-dom": "^15.5.4", "react-fontawesome": "^1.6.1", "semantic-ui-css": "^2.2.10", - "semantic-ui-react": "^0.68.5" + "semantic-ui-react": "^0.68.5", + "webpack-merge": "^4.1.0" }, "devDependencies": { "@types/webpack-env": "^1.13.0", diff --git a/webpack/base.config.js b/webpack/base.config.js new file mode 100644 index 0000000..256a675 --- /dev/null +++ b/webpack/base.config.js @@ -0,0 +1,33 @@ +const path = require("path"); +const webpack = require("webpack"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); + +module.exports = { + devtool: "inline-source-map", + output: { + path: path.resolve(__dirname, "..", "build"), + filename: "bundle.js" + }, + resolve: { + extensions: [".ts", ".tsx", ".js"], + alias: { + app: path.resolve(__dirname, "..", "app") + } + }, + module: { + rules: [ + { test: /\.css$/, loader: "style-loader!css-loader" }, + { test: /\.(ttf|eot|svg|woff(2)?|png|jpg)(\?[a-z0-9=&.]+)?$/, loader: "file-loader" } + ] + }, + plugins: [ + new HtmlWebpackPlugin({ + template: "./app/index.html" + }), + new webpack.NamedModulesPlugin(), + new webpack.HotModuleReplacementPlugin() + ], + devServer: { + hot: true + } +}; diff --git a/webpack/dev.config.js b/webpack/dev.config.js index ebc6c48..b7d2c42 100644 --- a/webpack/dev.config.js +++ b/webpack/dev.config.js @@ -1,8 +1,8 @@ -const path = require("path"); const webpack = require("webpack"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); +const webpackMerge = require("webpack-merge"); +const base = require("./base.config"); -module.exports = { +module.exports = webpackMerge.smart(base, { entry: [ "react-hot-loader/patch", "webpack-dev-server/client?http://localhost:8080", @@ -10,31 +10,16 @@ module.exports = { "./app/script/index.tsx" ], devtool: "inline-source-map", - output: { - path: path.resolve(__dirname, "../build"), - filename: "bundle.js" - }, - resolve: { - extensions: [".ts", ".tsx", ".js"], - alias: { - app: path.resolve("./app") - } - }, module: { rules: [ { test: /\.tsx?$/, loaders: ["react-hot-loader/webpack", "awesome-typescript-loader"] }, - { test: /\.css$/, loader: "style-loader!css-loader" }, - { test: /\.(ttf|eot|svg|woff(2)?|png|jpg)(\?[a-z0-9=&.]+)?$/, loader: "file-loader" } ] }, plugins: [ - new HtmlWebpackPlugin({ - template: "./app/index.html" - }), new webpack.NamedModulesPlugin(), new webpack.HotModuleReplacementPlugin() ], devServer: { hot: true } -}; +}); diff --git a/webpack/prod.config.js b/webpack/prod.config.js index c55f97f..5568a85 100644 --- a/webpack/prod.config.js +++ b/webpack/prod.config.js @@ -1,32 +1,16 @@ -const path = require("path"); -const webpack = require("webpack"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); +const webpackMerge = require("webpack-merge"); +const base = require("./base.config"); -module.exports = { +module.exports = webpackMerge.smart(base, { entry: [ "./app/script/index.tsx" ], devtool: "none", - output: { - path: path.resolve(__dirname, "../dist"), - filename: "bundle.js" - }, - resolve: { - extensions: [".ts", ".tsx", ".js"], - alias: { - app: path.resolve("./app") - } - }, module: { rules: [ { test: /\.tsx?$/, loader: "awesome-typescript-loader" }, - { test: /\.css$/, loader: "style-loader!css-loader" }, - { test: /\.(ttf|eot|svg|woff(2)?|png|jpg)(\?[a-z0-9=&.]+)?$/, loader: "file-loader" } ] }, plugins: [ - new HtmlWebpackPlugin({ - template: "./app/index.html" - }) ] -}; +}); diff --git a/yarn.lock b/yarn.lock index fdc7beb..80202f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3523,6 +3523,12 @@ webpack-dev-server@^2.4.4: webpack-dev-middleware "^1.10.2" yargs "^6.0.0" +webpack-merge@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.0.tgz#6ad72223b3e0b837e531e4597c199f909361511e" + dependencies: + lodash "^4.17.4" + webpack-sources@^0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"