Skip to content

Instantly share code, notes, and snippets.

@joshuacrass
Last active December 12, 2022 18:42
Show Gist options
  • Save joshuacrass/6d1c4fd689d2b0f62432af473d8343e4 to your computer and use it in GitHub Desktop.
Save joshuacrass/6d1c4fd689d2b0f62432af473d8343e4 to your computer and use it in GitHub Desktop.
react-starter Webpack development config file
// webpack-dev-config.js
// configuration data related to development only
const path = require("path");
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const paths = require("./paths");
// import common webpack config
const common = require("./webpack-common-config.js");
module.exports = merge(common, {
entry: [paths.appIndexJs],
mode: "development",
// devtool option controls if and how source maps are generated.
// see https://webpack.js.org/configuration/devtool/
// If you find that you need more control of source map generation,
// see https://webpack.js.org/plugins/source-map-dev-tool-plugin/
devtool: "eval",
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development")
}
})
],
module: {
rules: [
{
// look for .js or .jsx files
test: /\.(js|jsx)$/,
// in the `src` directory
include: path.resolve(paths.appSrc),
exclude: /(node_modules)/,
use: {
// use babel for transpiling JavaScript files
loader: "babel-loader",
options: {
presets: ["@babel/react"]
}
}
},
{
// look for .css or .scss files
test: /\.(css|scss)$/,
// in the `src` directory
include: [path.resolve(paths.appSrc)],
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
discardDuplicates: true,
importLoaders: 1,
// This enables local scoped CSS based in CSS Modules spec
modules: true,
// generates a unique name for each class (e.g. app__app___2x3cr)
localIdentName: "[name]__[local]___[hash:base64:5]"
}
}
// Add additional loaders here. (e.g. sass-loader)
]
}
]
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment