-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
89 lines (88 loc) · 2.75 KB
/
webpack.config.js
File metadata and controls
89 lines (88 loc) · 2.75 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
const webpack = require('webpack');
const { resolve } = require('path');
const HTMLwebpackPlugin = require('html-webpack-plugin');
const MiniCSSextractPlugin = require('mini-css-extract-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = {
entry: ["@babel/polyfill", resolve(__dirname, 'src', 'index.js')],
output: {
path: resolve(__dirname, 'build'),
filename: () => {
return process.env.NODE_ENV === 'development' ? 'app.js' : 'app.[contenthash].js';
}
},
devtool: 'eval-source-map',
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
},
{
test: /\.ogg|mp3|wav|mpe?g|png|jpe?g|gif|svg$/i,
loader: 'file-loader',
options: {
name() {
if (process.env.NODE_ENV === 'development') {
return '[path][name].[ext]';
}
return '[contenthash].[ext]';
}
}
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: MiniCSSextractPlugin.loader,
options: {
publicPath: ''
}
},
{
loader: "css-loader"
},
{
loader: "sass-loader"
}
]
},
]
},
plugins: [
new webpack.ProvidePlugin({
"React": "react"
}),
new HTMLwebpackPlugin({
template: resolve(__dirname, 'public', 'index.html')
}),
new MiniCSSextractPlugin({
filename: () => {
return process.env.NODE_ENV === 'development' ? 'app.css' : 'app.[contenthash].css';
}
}),
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: resolve(__dirname, "public"),
globOptions: {
ignore: ["**/*.html"]
}
}
],
})
// new BundleAnalyzerPlugin()
]
}