-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
140 lines (139 loc) · 4.46 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
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
mode: process.env.NODE_ENV,
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public'),
filename: './assets/js/app.js',
},
plugins: [
/*
* Move compiled .scss to an actual .css file in
* the final build.
*/
new MiniCssExtractPlugin({
filename: './assets/css/main.css',
}),
/*
* Generate index.html page for the app.
*/
new HtmlWebpackPlugin({
title: 'My App',
template: './src/index.html',
}),
],
module: {
rules: [
/*
* Process JavaScript files and run them
* through babel.
*
* Note: The `babel-preset-react-app` is
* important, to give us public class field
* syntax (i.e. fat arrows and better this
* binding).
*/
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
babelrc: false,
presets: ['@babel/preset-react'],
},
},
/*
* Process images that were imported from
* JavaScript files.
*/
{
test: /\.(svg|png|jpg|gif)$/,
issuer: /\.js/,
use: [
{
loader: 'file-loader',
options: {
outputPath: './assets/img',
name: '[name].[ext]',
publicPath: '/assets/img',
},
},
],
},
/*
* Process Sass files, using the following
* loaders:
*
* 1. sass-loader: Compiles the Sass into CSS.
* 2. postcss-loader: Applies postcss and autoprefixer
* to CSS.
* 3. css-loader: Gets all the assets from @import
* and url() from within the CSS.
* 4. MiniCssExtractPlugin: Puts compiled CSS
* into a file, configured above.
*
* Note: Imported CSS files will also work.
*/
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle:
process.env.NODE_ENV === 'production'
? 'compressed'
: 'expanded',
},
},
},
],
},
/*
* Process images that were extracted from
* url() in .scss files, via `css-loader`.
*
* These need a custom public path so that
* the URLs resolve properly from the final
* CSS file.
*/
{
test: /\.(svg|png|jpg|gif)$/,
issuer: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: './assets/img',
name: '[name].[ext]',
publicPath: '../img',
},
},
],
},
/*
* Process font files that were extracted from
* url() in .scss files, via `css-loader`.
*/
{
test: /\.(ttf|woff|eot)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: './assets/font',
name: '[name].[ext]',
publicPath: '../font',
},
},
],
},
],
},
};