-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwebpack.config.js
179 lines (174 loc) · 6.07 KB
/
webpack.config.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
178
179
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
// This is the base URI for the webapp and is used when links get created for resources
// such as images and font files.
const publicPath = `/`;
module.exports = {
// Provides a source map for use in development.
// https://webpack.js.org/guides/development/#using-source-maps
devtool: 'inline-source-map',
devServer: {
publicPath,
watchContentBase: true,
open: true,
},
optimization: {
// Setting optimization.minimizer overrides the defaults provided by webpack,
// so we must also now specify a JS minimizer.
// https://github.com/webpack-contrib/mini-css-extract-plugin#minimizing-for-production
minimizer: [
new TerserJSPlugin({}),
new OptimizeCSSAssetsPlugin({})
],
},
plugins: [
// Clean the /dist folder before each build
// https://webpack.js.org/guides/output-management/#cleaning-up-the-dist-folder
new CleanWebpackPlugin(),
// Simplifies HTML file creation for dynamic hash names.
// https://webpack.js.org/guides/output-management/#setting-up-htmlwebpackplugin
new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "./index.html",
}),
// Replacement for deprecated extract-text-webpack-plugin
// https://github.com/webpack-contrib/mini-css-extract-plugin
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
// https://github.com/Urthen/case-sensitive-paths-webpack-plugin#readme
new CaseSensitivePathsPlugin(),
],
output: {
// Give the bundled output file a name. Use [name] for dynamically generated naming. Requires
// HtmlWebpackPlugin.
filename: '[name].js',
// Tell webpack where to put the bundled file.
path: path.resolve(__dirname, 'app'),
// You must set this if the app won't be served at `http://<app-url>:<port>/`.
// appnav is served at `/beta/ for example until its external release.
publicPath,
},
module: {
// These rules tell webpack how to load different file types. Without these, webpack can't load anything.
// https://webpack.js.org/guides/asset-management/#setup
rules: [
{
// Tell webpack how to load style files.
// https://webpack.js.org/guides/asset-management/#loading-css
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// Support hot-module-reload for style files in development.
hmr: process.env.NODE_ENV === 'development',
},
},
'css-loader',
'sass-loader',
],
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'less-loader',
options: {
paths: [path.resolve(__dirname, 'node_modules')],
},
},
],
},
{
// Tell webpack how to load images.
// https://webpack.js.org/guides/asset-management/#loading-images
test: /\.(png|jpg|gif|svg)$/i,
use: [
{
// Tell webpack to use url-loader to load images.
// https://webpack.js.org/loaders/url-loader/#root
loader: 'url-loader',
options: {
limit: 10000,
// url-loader is not suitable for larger images. Specify a fallback for files larger
// than the limit set above.
// https://webpack.js.org/loaders/file-loader/
fallback: 'file-loader',
},
},
],
},
{
// Tell webpack how to load font files.
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
// Tell webpack to use file-loader for font files.
// https://webpack.js.org/loaders/file-loader/
'file-loader',
],
},
{
// Tell webpack how to load xml files.
// Note: JSON data loading is built into webpack and requires no loading configuration.
// https://webpack.js.org/guides/asset-management/#loading-data
test: /\.xml$/,
use: [
// Tell webpack to use xml-loader for xml files.
// https://github.com/gisikw/xml-loader
'xml-loader',
],
},
{
// Tell webpack to check source files, before modification by other loaders (like babel-loader).
enforce: 'pre',
test: /\.(js|jsx)$/,
// Tell eslint to ignore node-modules.
exclude: /node_modules/,
// Tell webpack to use eslint-loader on js and jsx source files.
// https://webpack.js.org/loaders/eslint-loader/#install
loader: 'eslint-loader',
options: {
// The module build will fail if there are any eslint errors. Enforces best practices.
// https://webpack.js.org/loaders/eslint-loader/#failonerror-default-false
failOnError: true,
},
},
{
// Tell webpack how to load javascript and JSX files.
// https://webpack.js.org/configuration/configuration-languages/#babel-and-jsx
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
// Tell webpack to use babel-loader for js and jsx files.
// https://webpack.js.org/loaders/babel-loader/
loader: 'babel-loader',
},
},
{
// Tell webpack how to load html pages.
// https://webpack.js.org/loaders/html-loader/#root
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: [':data-src'],
minimize: true,
}
}
}
],
},
};