-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathwebpack.config.js
More file actions
107 lines (102 loc) · 3.53 KB
/
Copy pathwebpack.config.js
File metadata and controls
107 lines (102 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { devServer, stats } = require("./constants");
const getPluginsByEnv = require("./plugins");
module.exports = ({ analyze, production } = {}) => ({
devtool: !production && "source-map",
devServer: {
host: devServer.host,
port: devServer.port,
historyApiFallback: true,
},
entry: {
app: "./src/index.tsx",
},
mode: production ? "production" : "development",
module: {
rules: [
{
test: /\.(j|t)sx?/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
extends: path.resolve(__dirname, "..", "..", "..", "babel.config.json"),
presets: ["@babel/preset-env"],
},
},
],
},
// this rule processes any CSS written for this project.
// It applies PostCSS plugins and converts it to CSS Modules
{
test: /\.css/,
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: {
exportLocalsConvention: "camelCase",
localIdentName: "[name]__[local]--[hash:base64:5]",
},
sourceMap: !production,
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: ["postcss-preset-env"],
},
sourceMap: !production,
},
},
],
},
// this rule will handle any vanilla CSS imports out of node_modules; it does not apply PostCSS,
// nor does it convert the imported css to CSS Modules
// use case: importing antd component css
{
test: (filepath) => filepath.endsWith(".css"),
include: /node_modules/,
use: [{ loader: MiniCssExtractPlugin.loader }, { loader: "css-loader" }],
},
{
test: /\.svg$/,
use: [
{
loader: "babel-loader",
},
{
loader: "react-svg-loader",
options: {
tsx: true, // true outputs tags
},
},
],
},
{
test: /\.(png|jpe?g)/,
type: "asset/resource",
},
],
},
output: {
path: path.resolve(__dirname, "../", "dist"),
filename: "[name].[chunkhash].js",
publicPath: "/",
},
plugins: getPluginsByEnv(production, analyze),
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".png"],
mainFields: ["module", "main"],
symlinks: false,
},
stats: analyze ? "none" : stats,
});