Skip to content

Instantly share code, notes, and snippets.

@9jaswag
Created April 4, 2020 11:06
Show Gist options
  • Save 9jaswag/8f18ca33f2c89132610eb04deffae098 to your computer and use it in GitHub Desktop.
Save 9jaswag/8f18ca33f2c89132610eb04deffae098 to your computer and use it in GitHub Desktop.
Webpack config
//=== webpack.common.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./client/index.js",
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/i,
exclude: /node_modules/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: true
}
}
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"]
}
]
},
resolve: {
extensions: ["*", ".js", ".jsx"]
},
plugins: [
new HtmlWebpackPlugin({
template: "./client/index.html"
})
],
output: {
path: path.resolve(__dirname, "dist"),
publicPath: "/",
filename: "bundle.js"
}
};
//=== webpack.dev.js
const { DefinePlugin } = require("webpack");
const webpack = require("webpack");
module.exports = {
devtool: "eval-source-map",
mode: "development",
plugins: [
new webpack.HotModuleReplacementPlugin(),
new DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development")
}
})
],
devServer: {
contentBase: "./dist",
hot: true,
historyApiFallback: true,
publicPath: "/",
proxy: {
"/api/**": {
target: "http://localhost:3000",
changeOrigin: true,
secure: false,
pathRewrite: { "^/api": "" }
}
}
}
};
//=== webpack.config.js
const webpackMerge = require("webpack-merge");
const commonConfig = require("./webpack.common.js");
module.exports = ({ env }) => {
const envConfig = require(`./webpack.${env}.js`);
return webpackMerge(commonConfig, envConfig);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment