@stanlemon/webdev 0.1.1 → 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.
package/jest.setup.js CHANGED
@@ -1 +1 @@
1
- import "@testing-library/jest-dom";
1
+ require("@testing-library/jest-dom");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stanlemon/webdev",
3
- "version": "0.1.1",
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",
@@ -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,14 +38,18 @@
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",
52
+ "url-loader": "^4.1.1",
51
53
  "webpack": "^5.65.0",
52
54
  "webpack-bundle-analyzer": "^4.5.0",
53
55
  "webpack-cli": "^4.9.1",
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,14 +99,29 @@ 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
- ...[!isDevelopment && new BundleAnalyzerPlugin()].filter(Boolean),
118
+ ...[
119
+ !isDevelopment &&
120
+ new BundleAnalyzerPlugin({
121
+ analyzerMode: "static",
122
+ openAnalyzer: false,
123
+ }),
124
+ ].filter(Boolean),
101
125
  ...[isDevelopment && new ReactRefreshWebpackPlugin()].filter(Boolean),
102
126
  ],
103
127
  };