-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebpack.config.js
More file actions
133 lines (126 loc) · 2.7 KB
/
Copy pathwebpack.config.js
File metadata and controls
133 lines (126 loc) · 2.7 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
133
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const commonConfig = {
devtool: 'eval-cheap-module-source-map',
resolve: {
extensions: ['.js', '.jsx'],
// Note: Separate aliases are required for aliases to work in unit tests. These should
// be added in package.json in the jest configuration.
alias: {
'@ml': path.resolve(__dirname, 'src'),
'@public': path.resolve(__dirname, 'public')
}
},
output: {
filename: '[name].js',
library: {
type: 'umd'
}
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader'
},
{test: /\.css$/, use: ['style-loader', 'css-loader']},
{
test: /\.jsx$/,
enforce: 'pre',
exclude: /(node_modules)/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react', '@babel/preset-env'],
plugins: ['@babel/plugin-transform-class-properties']
}
}
]
},
{
test: /\.(png|gif|svg)$/,
type: 'asset/inline',
},
{
type: 'asset/resource',
test: /src\/oceans\/model.json$/,
generator: {
filename: 'assets/models/[name][ext]?[contenthash]'
}
},
{
test: /\.(mp3|ogg|wav)$/,
type: 'asset/resource',
generator: {
filename: 'assets/sounds/[name][ext]?[contenthash]'
}
}
]
},
performance: {
assetFilter: function(assetFilename) {
return /^assets\//.test(assetFilename);
},
maxAssetSize: 300000,
maxEntrypointSize: 10500000
},
plugins: [
new (require('webpack').ProvidePlugin)({
process: 'process/browser'
})
]
};
const firstConfigOnly = {
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: 'src/oceans/*.bin',
to: 'assets/models/[name][ext]'
}
]
})
]
};
const externalConfig = {
externals: {
lodash: 'lodash',
radium: 'radium',
react: 'react',
'react-dom': 'react-dom'
}
};
const defaultConfig = [
{
entry: {
assetPath: './src/oceans/assetPath.js'
},
...commonConfig,
...firstConfigOnly,
...externalConfig
},
{
entry: {
oceans: './src/oceans/index.jsx'
},
...commonConfig
}
];
const productionConfig = [
{
entry: {
main: './src/index.js'
},
...commonConfig,
...externalConfig
}
];
module.exports = (env, argv) => {
if (argv.mode === 'production') {
return [...defaultConfig, ...productionConfig];
}
return defaultConfig;
};