@stanlemon/webdev 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/webpack.config.js +39 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/webdev",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "My typical web development setup, but without all the copy and paste.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"babel-loader": "^8.2.3",
|
|
39
39
|
"clean-webpack-plugin": "^4.0.0",
|
|
40
40
|
"css-loader": "^6.5.1",
|
|
41
|
+
"dotenv": "^10.0.0",
|
|
41
42
|
"html-webpack-plugin": "^5.5.0",
|
|
42
43
|
"identity-obj-proxy": "^3.0.0",
|
|
43
44
|
"jest": "^27.4.5",
|
|
@@ -48,7 +49,6 @@
|
|
|
48
49
|
"react-refresh": "^0.11.0",
|
|
49
50
|
"style-loader": "^3.3.1",
|
|
50
51
|
"typescript": "^4.5.4",
|
|
51
|
-
"url-loader": "^4.1.1",
|
|
52
52
|
"webpack": "^5.65.0",
|
|
53
53
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
54
54
|
"webpack-cli": "^4.9.1",
|
package/webpack.config.js
CHANGED
|
@@ -5,18 +5,40 @@ import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
|
5
5
|
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
6
6
|
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
7
7
|
import { CleanWebpackPlugin } from "clean-webpack-plugin";
|
|
8
|
+
import { config as dotenv } from "dotenv";
|
|
9
|
+
|
|
10
|
+
dotenv();
|
|
8
11
|
|
|
9
12
|
const babelOptions = JSON.parse(
|
|
10
13
|
readFileSync(new URL("./.babelrc.json", import.meta.url))
|
|
11
14
|
);
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
// Entry points, which can be separated by a semi-colon
|
|
17
|
+
const WEBDEV_ENTRY = process.env.WEBDEV_ENTRY ?? "./src/index.tsx";
|
|
18
|
+
// HTML pages to create, which can be separated by a semi-colon
|
|
19
|
+
// If you prefix a page with a ! it will disable script injection
|
|
20
|
+
// The filename from the supplied path is used as the filename of the resulting file
|
|
21
|
+
const WEBDEV_HTML = process.env.WEBDEV_HTML ?? "./index.html";
|
|
22
|
+
// Proxy path's can be designated as path@host, separated by semi-colons
|
|
23
|
+
// For example /api@http://localhost:3000;/auth@http://localhost:4000
|
|
24
|
+
const WEBDEV_PROXY = process.env.WEBDEV_PROXY ?? "";
|
|
25
|
+
const NODE_ENV = process.env.NODE_ENV ?? "development";
|
|
26
|
+
|
|
27
|
+
const proxy = {};
|
|
28
|
+
WEBDEV_PROXY.split(";").forEach((entry) => {
|
|
29
|
+
if (entry.indexOf("@") === -1) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const path = entry.substring(0, entry.indexOf("@"));
|
|
33
|
+
const host = entry.substring(entry.indexOf("@") + 1);
|
|
34
|
+
proxy[path] = host;
|
|
35
|
+
});
|
|
14
36
|
|
|
15
|
-
const isDevelopment =
|
|
37
|
+
const isDevelopment = NODE_ENV !== "production";
|
|
16
38
|
|
|
17
39
|
export default {
|
|
18
40
|
mode: isDevelopment ? "development" : "production",
|
|
19
|
-
entry:
|
|
41
|
+
entry: WEBDEV_ENTRY.split(";"),
|
|
20
42
|
output: {
|
|
21
43
|
filename: "[name].[contenthash].js",
|
|
22
44
|
path: path.resolve("./", "dist"),
|
|
@@ -25,6 +47,7 @@ export default {
|
|
|
25
47
|
devServer: {
|
|
26
48
|
hot: true,
|
|
27
49
|
historyApiFallback: true,
|
|
50
|
+
proxy,
|
|
28
51
|
},
|
|
29
52
|
optimization: {
|
|
30
53
|
moduleIds: "deterministic",
|
|
@@ -79,7 +102,7 @@ export default {
|
|
|
79
102
|
},
|
|
80
103
|
{
|
|
81
104
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
82
|
-
|
|
105
|
+
type: "asset/resource",
|
|
83
106
|
},
|
|
84
107
|
],
|
|
85
108
|
},
|
|
@@ -90,11 +113,20 @@ export default {
|
|
|
90
113
|
plugins: [
|
|
91
114
|
...[
|
|
92
115
|
new CleanWebpackPlugin(),
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
...WEBDEV_HTML.split(";").map((html) => {
|
|
117
|
+
let inject = true;
|
|
118
|
+
if (html.substring(0, 1) === "!") {
|
|
119
|
+
html = html.substring(1);
|
|
120
|
+
inject = false;
|
|
121
|
+
}
|
|
122
|
+
return new HtmlWebpackPlugin({
|
|
123
|
+
filename: path.basename(html),
|
|
124
|
+
template: html,
|
|
125
|
+
inject,
|
|
126
|
+
});
|
|
95
127
|
}),
|
|
96
128
|
new webpack.DefinePlugin({
|
|
97
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
129
|
+
"process.env.NODE_ENV": JSON.stringify(NODE_ENV),
|
|
98
130
|
}),
|
|
99
131
|
],
|
|
100
132
|
...[
|