@stanlemon/webdev 0.1.4 → 0.1.5

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 +2 -1
  2. package/webpack.config.js +24 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stanlemon/webdev",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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",
package/webpack.config.js CHANGED
@@ -5,18 +5,27 @@ 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
+ const NODE_ENV = process.env.NODE_ENV ?? "development";
14
23
 
15
- const isDevelopment = ENV !== "production";
24
+ const isDevelopment = NODE_ENV !== "production";
16
25
 
17
26
  export default {
18
27
  mode: isDevelopment ? "development" : "production",
19
- entry: ["./src/index.tsx"],
28
+ entry: WEBDEV_ENTRY.split(";"),
20
29
  output: {
21
30
  filename: "[name].[contenthash].js",
22
31
  path: path.resolve("./", "dist"),
@@ -90,11 +99,20 @@ export default {
90
99
  plugins: [
91
100
  ...[
92
101
  new CleanWebpackPlugin(),
93
- new HtmlWebpackPlugin({
94
- template: path.resolve("./", "index.html"),
102
+ ...WEBDEV_HTML.split(";").map((html) => {
103
+ let inject = true;
104
+ if (html.substring(0, 1) === "!") {
105
+ html = html.substring(1);
106
+ inject = false;
107
+ }
108
+ return new HtmlWebpackPlugin({
109
+ filename: path.basename(html),
110
+ template: html,
111
+ inject,
112
+ });
95
113
  }),
96
114
  new webpack.DefinePlugin({
97
- "process.env.NODE_ENV": JSON.stringify(ENV),
115
+ "process.env.NODE_ENV": JSON.stringify(NODE_ENV),
98
116
  }),
99
117
  ],
100
118
  ...[