-
Notifications
You must be signed in to change notification settings - Fork 24
/
webpack.config.common.js
177 lines (173 loc) · 4.76 KB
/
webpack.config.common.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path-browserify");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
// modules that are not compatible with IE11
const includedNodeModules = ["query-string", "strict-uri-encode"];
const STYLES_PATH = "app/assets/src/styles";
const config = {
entry: `${path.resolve(__dirname, "app/assets/src/")}/index.tsx`,
output: {
path: path.resolve(__dirname, "app/assets/"),
filename: "dist/[name].bundle.min.js",
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
alias: {
"~": path.resolve(__dirname, "app/assets/src"),
"~ui": path.resolve(__dirname, "app/assets/src/components/ui"),
"~utils": path.resolve(__dirname, "app/assets/src/components/utils"),
styles: path.resolve(__dirname, STYLES_PATH),
},
fallback: {
util: require.resolve("util"),
path: require.resolve("path-browserify"),
process: require.resolve("process/browser"), // for env var __dirname
},
},
plugins: [
new MiniCssExtractPlugin({
filename: "dist/[name].bundle.min.css",
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
devtool: "source-map",
target: "web",
module: {
rules: [
{
test: /.(js|ts)x?$/,
exclude: new RegExp(
`/node_modules/(?!(${includedNodeModules.join("|")})/).*/`,
),
loader: "babel-loader",
},
{
// Use CSS modules for new files.
test: /\.(sa|sc|c)ss$/,
exclude: [
path.resolve(__dirname, "node_modules/"),
path.resolve(__dirname, STYLES_PATH),
path.resolve(__dirname, "app/assets/src/loader.scss"),
],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 2,
modules: {
mode: "local",
localIdentName: "[local]-[hash:base64:5]",
},
},
},
{
loader: "postcss-loader",
options: {
ident: "postcss",
sourceMap: true,
plugins: loader => [require("cssnano")({ preset: "default" })],
},
},
{
loader: "sass-loader",
options: {
sourceMap: true,
implementation: require("sass"),
},
},
],
},
{
// Sass / Scss loader for legacy files in assets/src/styles.
test: /\.(sa|sc|c)ss$/,
include: [
path.resolve(__dirname, "node_modules/"),
path.resolve(__dirname, STYLES_PATH),
path.resolve(__dirname, "app/assets/src/loader.scss"),
],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 2,
modules: {
mode: "global",
},
},
},
{
loader: "postcss-loader",
options: {
ident: "postcss",
sourceMap: true,
plugins: loader => [require("cssnano")({ preset: "default" })],
},
},
{
loader: "sass-loader",
options: {
sourceMap: true,
implementation: require("sass"),
},
},
],
},
{
test: /\.(png|eot|ttf|svg|gif)$/,
loader: "url-loader",
options: {
limit: 10000,
name: "fonts/[name].[ext]",
mimetype: "application/font-woff",
publicPath: url => {
return `/assets${url.replace(/fonts/, "")}`;
},
},
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader",
options: {
limit: 10000,
name: "fonts/[name].[ext]",
mimetype: "application/font-woff",
publicPath: url => {
return `/assets${url.replace(/fonts/, "")}`;
},
},
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
default: false, // disable default cache group
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: "all",
enforce: true, // always create a chunk
name: "vendors",
},
},
},
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: true,
// We need this option for rails react_component.
keep_fnames: true,
},
parallel: true,
sourceMap: true,
}),
],
},
};
module.exports = config;