-
Notifications
You must be signed in to change notification settings - Fork 58
/
webpack.config.js
83 lines (81 loc) · 2.33 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
const webpack = require("webpack");
const paths = require("./config/paths");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { merge } = require("webpack-merge");
const loadPreset = require("./config/presets/loadPreset");
const loadConfig = (mode) => require(`./config/webpack.${mode}.js`)(mode);
const nodeExternals = require("webpack-node-externals");
module.exports = function (env) {
const { mode = "production" } = env || {};
return merge(
{
mode,
entry: `${paths.srcPath}/index.js`,
output: {
path: paths.distPath,
filename: "index.js",
libraryTarget: "umd",
},
externals: [
nodeExternals(),
{
react: {
commonjs: "react",
commonjs2: "react",
amd: "react",
root: "React",
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "react-dom",
root: "ReactDOM",
},
},
],
module: {
rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.js$/,
use: ["babel-loader"],
exclude: path.resolve(__dirname, "node_modules"),
},
// Images: Copy image files to build folder
{ test: /\.(?:ico|gif|png|jpg|jpeg)$/i, type: "asset/resource" },
// Fonts and SVGs: Inline files
{ test: /\.(woff(2)?|eot|ttf|otf|svg|)$/, type: "asset/inline" },
],
},
resolve: {
modules: [paths.srcPath, "node_modules"],
extensions: [".js", ".jsx", ".json"],
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
},
},
target: "node",
plugins: [
// new webpack.EnvironmentPlugin({
// // Configure environment variables here.
// ENVIRONMENT: "browser",
// }),
new CleanWebpackPlugin(),
new webpack.ProgressPlugin(),
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: [require.resolve("buffer/"), "Buffer"],
}),
],
},
loadConfig(mode),
loadPreset(env)
);
};