-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (96 loc) · 3.21 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
const webpack = require("webpack");
const paths = require("./config/paths");
const path = require("path");
const ManifestPlugin = require("webpack-manifest-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { merge } = require("webpack-merge");
const loadPreset = require("./config/presets/loadPreset");
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
const loadConfig = (mode) => require(`./config/webpack.${mode}.js`)(mode);
module.exports = function (env) {
const { mode = "production" } = env || {};
return merge(
{
mode,
entry: `${paths.srcPath}/index.js`,
output: {
path: paths.distPath,
filename: "[name].bundle.js",
publicPath: "/",
},
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"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
fs: false,
path: require.resolve("path-browserify"),
zlib: require.resolve("browserify-zlib"),
},
// Fix for using `yarn link "near-social-vm"`
alias: {
react: path.resolve(__dirname, "./node_modules/react"),
"react-dom": path.resolve(__dirname, "./node_modules/react-dom"),
"near-api-js": path.resolve(__dirname, "./node_modules/near-api-js"),
},
},
plugins: [
new webpack.EnvironmentPlugin({
// Configure environment variables here.
ENVIRONMENT: "browser",
}),
new CleanWebpackPlugin(),
// Copies files from target to destination folder
new CopyWebpackPlugin({
patterns: [
{
from: paths.publicPath,
to: "assets",
globOptions: {
ignore: ["*.DS_Store"],
},
noErrorOnMissing: true,
},
],
}),
new HTMLWebpackPlugin({
template: `${paths.publicPath}/index.html`,
favicon: `${paths.publicPath}/favicon.png`,
robots: `${paths.publicPath}/robots.txt`,
}),
new webpack.ProgressPlugin(),
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: [require.resolve("buffer/"), "Buffer"],
}),
new ManifestPlugin.WebpackManifestPlugin(),
],
},
loadConfig(mode),
loadPreset(env)
);
};