-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
96 lines (94 loc) · 2.46 KB
/
Copy pathwebpack.config.js
File metadata and controls
96 lines (94 loc) · 2.46 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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Dotenv = require("dotenv-webpack");
const CopyPlugin = require("copy-webpack-plugin");
module.exports = (env, argv) => {
const isProd = argv.mode === "production";
return {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "build"),
filename: "index.js",
publicPath: "",
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: "babel-loader",
},
{
test: /\.css$/,
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"postcss-loader",
],
},
{
test: /\.scss$/,
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"postcss-loader",
"sass-loader",
],
},
],
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
plugins: [
new MiniCssExtractPlugin({
filename: "index.css",
}),
new Dotenv({
path: isProd
? path.resolve(__dirname, ".env") // Production builds load .env
: path.resolve(__dirname, ".env.local"), // Development loads .env.local
safe: false,
allowEmptyValues: true,
systemvars: false,
silent: false,
}),
// Copy all PHP files to the build folder, excluding unnecessary files.
new CopyPlugin({
patterns: [
{
from: "**/*.php",
context: __dirname,
globOptions: {
ignore: [
"**/node_modules/**",
"**/build/**",
"**/.DS_Store",
"**/.env",
"**/.env.local",
"**/.gitignore",
"**/*.map",
"**/src/**",
],
},
},
],
}),
],
devServer: {
static: {
directory: path.join(__dirname, "build"),
},
compress: true,
port: 3002, // your chosen port
hot: false, // disable hot module replacement
open: false,
watchFiles: ["src/**/*"],
devMiddleware: {
writeToDisk: true, // write assets to disk in dev mode
},
allowedHosts: "all", // Allow any host
},
devtool: isProd ? "source-map" : "eval-source-map",
};
};