@stanlemon/webdev 0.1.3 → 0.1.7

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.
Files changed (2) hide show
  1. package/package.json +4 -3
  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",
3
+ "version": "0.1.7",
4
4
  "description": "My typical web development setup, but without all the copy and paste.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -19,8 +19,6 @@
19
19
  "lint:format": "eslint --fix --ext js,jsx,ts,tsx ./"
20
20
  },
21
21
  "dependencies": {
22
- "react": "^17.0.2",
23
- "react-dom": "^17.0.2",
24
22
  "@babel/core": "^7.16.5",
25
23
  "@babel/preset-env": "^7.16.5",
26
24
  "@babel/preset-react": "^7.16.5",
@@ -40,11 +38,14 @@
40
38
  "babel-loader": "^8.2.3",
41
39
  "clean-webpack-plugin": "^4.0.0",
42
40
  "css-loader": "^6.5.1",
41
+ "dotenv": "^10.0.0",
43
42
  "html-webpack-plugin": "^5.5.0",
44
43
  "identity-obj-proxy": "^3.0.0",
45
44
  "jest": "^27.4.5",
46
45
  "less": "^4.1.2",
47
46
  "less-loader": "^10.2.0",
47
+ "react": "^17.0.2",
48
+ "react-dom": "^17.0.2",
48
49
  "react-refresh": "^0.11.0",
49
50
  "style-loader": "^3.3.1",
50
51
  "typescript": "^4.5.4",
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
- const ENV = process.env.NODE_ENV ?? "development";
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_HTML ?? "";
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 = ENV !== "production";
37
+ const isDevelopment = NODE_ENV !== "production";
16
38
 
17
39
  export default {
18
40
  mode: isDevelopment ? "development" : "production",
19
- entry: ["./src/index.tsx"],
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
- loader: "url-loader",
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
- new HtmlWebpackPlugin({
94
- template: path.resolve("./", "index.html"),
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(ENV),
129
+ "process.env.NODE_ENV": JSON.stringify(NODE_ENV),
98
130
  }),
99
131
  ],
100
132
  ...[