forked from atorov/react-hooks-p5js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
132 lines (124 loc) · 3.81 KB
/
webpack.config.js
File metadata and controls
132 lines (124 loc) · 3.81 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
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
const path = require('path')
const webpack = require('webpack')
const Autoprefixer = require('autoprefixer')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const NODE_MODULES = path.resolve(__dirname, 'node_modules')
const EXTERNALS = path.resolve(__dirname, 'externals')
const STORAGE = path.resolve(__dirname, '__storage__')
const EXCLUDE_DEFAULT = [NODE_MODULES, EXTERNALS, STORAGE]
const SRC = path.resolve(__dirname, 'src')
const DIST = path.resolve(__dirname, 'build/www')
const NODE_ENV = process.env.NODE_ENV
const MODE = NODE_ENV !== 'development' ? 'production' : 'development'
process.env.BABEL_ENV = MODE
const config = {
mode: MODE,
resolve: {
extensions: ['.js', '.jsx'],
alias: { 'react-dom': '@hot-loader/react-dom' },
},
entry: [
'core-js/stable',
'regenerator-runtime/runtime',
SRC,
],
output: {
path: DIST,
publicPath: '/',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.css$/,
include: SRC,
exclude: EXCLUDE_DEFAULT,
use: (() => {
if (MODE === 'development') {
return [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => ([Autoprefixer]),
},
},
]
}
return [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => ([Autoprefixer]),
},
},
]
})(),
},
{
test: /\.jsx?$/,
include: SRC,
exclude: EXCLUDE_DEFAULT,
use: { loader: 'babel-loader' },
},
],
},
plugins: [
new webpack.WatchIgnorePlugin(EXCLUDE_DEFAULT),
new HtmlWebpackPlugin({
filename: DIST + '/index.html',
template: SRC + '/index.ejs',
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash:4].css',
}),
new CopyWebpackPlugin(
[
{
from: SRC + '/assets/img/favicon.png',
to: DIST,
},
{
from: SRC + '/assets/img',
to: DIST + '/img',
},
{
from: SRC + '/assets/audio',
to: DIST + '/audio',
},
],
{
ignore: ['.DS_Store'],
},
),
],
}
if (MODE === 'production') {
config.output.chunkFilename = '[name].[chunkhash:4].js'
config.output.filename = '[name].[chunkhash:4].js'
config.optimization = {
splitChunks: { chunks: 'initial' },
runtimeChunk: { name: 'manifest' },
}
}
if (MODE === 'development') {
config.devServer = {
historyApiFallback: true,
disableHostCheck: true,
stats: 'errors-only',
overlay: true,
hotOnly: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
ignored: EXCLUDE_DEFAULT,
},
}
config.plugins.push(new webpack.HotModuleReplacementPlugin())
}
module.exports = config