@workleap/webpack-configs 1.0.3 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @workleap/webpack-configs
2
2
 
3
+ ## 1.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#131](https://github.com/gsoft-inc/wl-web-configs/pull/131) [`11bb287`](https://github.com/gsoft-inc/wl-web-configs/commit/11bb287847b4f525faa83abd23e46c56f58e41f4) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added a default key to exports
8
+
9
+ ## 1.0.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#127](https://github.com/gsoft-inc/wl-web-configs/pull/127) [`f440b12`](https://github.com/gsoft-inc/wl-web-configs/commit/f440b1251e2b3c1960dfc7f68bd090f573ec67d6) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Fix environment variables
14
+
3
15
  ## 1.0.3
4
16
 
5
17
  ### Patch Changes
package/dist/build.d.ts CHANGED
@@ -15,13 +15,13 @@ interface DefineBuildConfigOptions {
15
15
  cacheDirectory?: string;
16
16
  moduleRules?: NonNullable<Configuration["module"]>["rules"];
17
17
  plugins?: Configuration["plugins"];
18
- htmlWebpackPlugin?: false | HtmlWebpackPlugin.Options;
18
+ htmlWebpackPlugin?: boolean | HtmlWebpackPlugin.Options;
19
19
  miniCssExtractPluginOptions?: MiniCssExtractPluginOptions;
20
20
  minify?: boolean;
21
21
  cssModules?: boolean;
22
- environmentVariables?: Record<string, string | undefined>;
22
+ environmentVariables?: Record<string, unknown>;
23
23
  transformers?: WebpackConfigTransformer[];
24
- profile?: boolean;
24
+ verbose?: boolean;
25
25
  }
26
26
  declare function defineBuildConfig(swcConfig: Config, options?: DefineBuildConfigOptions): Configuration;
27
27
 
package/dist/build.js CHANGED
@@ -1,2 +1,3 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-2Q5IGCCY.js';
2
- import './chunk-EF2WO5MC.js';
1
+ export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-GFNG2PBM.js';
2
+ import './chunk-P2Z3EEVF.js';
3
+ import './chunk-QJI26K46.js';
@@ -1,4 +1,5 @@
1
- import { applyTransformers } from './chunk-EF2WO5MC.js';
1
+ import { isObject } from './chunk-P2Z3EEVF.js';
2
+ import { applyTransformers } from './chunk-QJI26K46.js';
2
3
  import HtmlWebpackPlugin from 'html-webpack-plugin';
3
4
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
5
  import { createRequire } from 'node:module';
@@ -29,7 +30,15 @@ function defineMiniCssExtractPluginConfig(options = {}) {
29
30
  filename
30
31
  };
31
32
  }
33
+ function preflight(options) {
34
+ if (options.publicPath) {
35
+ if (!options.publicPath.endsWith("/")) {
36
+ throw new Error('[webpack-configs] The "publicPath" must end with a "/".');
37
+ }
38
+ }
39
+ }
32
40
  function defineBuildConfig(swcConfig, options = {}) {
41
+ preflight(options);
33
42
  const {
34
43
  entry = path.resolve("./src/index.tsx"),
35
44
  outputPath = path.resolve("dist"),
@@ -47,7 +56,7 @@ function defineBuildConfig(swcConfig, options = {}) {
47
56
  // "process.env" is always available.
48
57
  environmentVariables = {},
49
58
  transformers = [],
50
- profile = false
59
+ verbose = false
51
60
  } = options;
52
61
  const config = {
53
62
  mode: "production",
@@ -99,7 +108,7 @@ function defineBuildConfig(swcConfig, options = {}) {
99
108
  })
100
109
  ]
101
110
  } : void 0,
102
- infrastructureLogging: profile ? {
111
+ infrastructureLogging: verbose ? {
103
112
  appendOnly: true,
104
113
  level: "verbose",
105
114
  debug: /PackFileCache/
@@ -155,18 +164,23 @@ function defineBuildConfig(swcConfig, options = {}) {
155
164
  }
156
165
  },
157
166
  plugins: [
158
- htmlWebpackPlugin && new HtmlWebpackPlugin(htmlWebpackPlugin),
167
+ htmlWebpackPlugin && new HtmlWebpackPlugin(isObject(htmlWebpackPlugin) ? htmlWebpackPlugin : defineBuildHtmlWebpackPluginConfig()),
159
168
  new MiniCssExtractPlugin(miniCssExtractPluginOptions),
169
+ // Stringify the environment variables because the plugin does a direct text replacement. Otherwise, "production" would become production
170
+ // after replacement and cause an undefined var error because the production var doesn't exist.
171
+ // For more information, view: https://webpack.js.org/plugins/define-plugin.
160
172
  new DefinePlugin({
161
- // Webpack automatically stringify object literals.
162
- "process.env": environmentVariables
173
+ "process.env": Object.keys(environmentVariables).reduce((acc, key) => {
174
+ acc[key] = JSON.stringify(environmentVariables[key]);
175
+ return acc;
176
+ }, {})
163
177
  }),
164
178
  ...plugins
165
179
  ].filter(Boolean)
166
180
  };
167
181
  const transformedConfig = applyTransformers(config, transformers, {
168
182
  environment: "build",
169
- profile
183
+ verbose
170
184
  });
171
185
  return transformedConfig;
172
186
  }
@@ -1,5 +1,5 @@
1
1
  import { isObject } from './chunk-P2Z3EEVF.js';
2
- import { applyTransformers } from './chunk-EF2WO5MC.js';
2
+ import { applyTransformers } from './chunk-QJI26K46.js';
3
3
  import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
4
4
  import HtmlWebpackPlugin from 'html-webpack-plugin';
5
5
  import { createRequire } from 'node:module';
@@ -23,15 +23,10 @@ function defineDevHtmlWebpackPluginConfig(options = {}) {
23
23
  function defineFastRefreshPluginConfig(options = {}) {
24
24
  return options;
25
25
  }
26
- function preflight(options) {
26
+ function preflight() {
27
27
  if (!require2.resolve("webpack-dev-server")) {
28
28
  throw new Error('[webpack-configs] To use the "dev" config, install https://www.npmjs.com/package/webpack-dev-server as a "devDependency".');
29
29
  }
30
- if (options.fastRefresh) {
31
- if (!require2.resolve("@pmmmwh/react-refresh-webpack-plugin")) {
32
- throw new Error('[webpack-configs] To use Webpack Fast Refresh, install https://www.npmjs.com/package/@pmmmwh/react-refresh-webpack-plugin as a "devDependency".');
33
- }
34
- }
35
30
  }
36
31
  function trySetSwcFastRefresh(config, enabled) {
37
32
  if (config?.jsc?.transform?.react) {
@@ -40,7 +35,7 @@ function trySetSwcFastRefresh(config, enabled) {
40
35
  return config;
41
36
  }
42
37
  function defineDevConfig(swcConfig, options = {}) {
43
- preflight(options);
38
+ preflight();
44
39
  const {
45
40
  entry = path.resolve("./src/index.tsx"),
46
41
  https = false,
@@ -57,7 +52,7 @@ function defineDevConfig(swcConfig, options = {}) {
57
52
  // "process.env" is always available.
58
53
  environmentVariables = {},
59
54
  transformers = [],
60
- profile = false
55
+ verbose = false
61
56
  } = options;
62
57
  const config = {
63
58
  mode: "development",
@@ -115,7 +110,7 @@ function defineDevConfig(swcConfig, options = {}) {
115
110
  removeEmptyChunks: false,
116
111
  splitChunks: false
117
112
  },
118
- infrastructureLogging: profile ? {
113
+ infrastructureLogging: verbose ? {
119
114
  appendOnly: true,
120
115
  level: "verbose",
121
116
  debug: /PackFileCache/
@@ -171,10 +166,15 @@ function defineDevConfig(swcConfig, options = {}) {
171
166
  }
172
167
  },
173
168
  plugins: [
174
- htmlWebpackPlugin && new HtmlWebpackPlugin(htmlWebpackPlugin),
169
+ htmlWebpackPlugin && new HtmlWebpackPlugin(isObject(htmlWebpackPlugin) ? htmlWebpackPlugin : defineDevHtmlWebpackPluginConfig()),
170
+ // Stringify the environment variables because the plugin does a direct text replacement. Otherwise, "production" would become production
171
+ // after replacement and cause an undefined var error.
172
+ // For more information, view: https://webpack.js.org/plugins/define-plugin/.
175
173
  new DefinePlugin({
176
- // Webpack automatically stringify object literals.
177
- "process.env": environmentVariables
174
+ "process.env": Object.keys(environmentVariables).reduce((acc, key) => {
175
+ acc[key] = JSON.stringify(environmentVariables[key]);
176
+ return acc;
177
+ }, {})
178
178
  }),
179
179
  fastRefresh && new ReactRefreshWebpackPlugin(isObject(fastRefresh) ? fastRefresh : defineFastRefreshPluginConfig()),
180
180
  ...plugins
@@ -182,7 +182,7 @@ function defineDevConfig(swcConfig, options = {}) {
182
182
  };
183
183
  const transformedConfig = applyTransformers(config, transformers, {
184
184
  environment: "dev",
185
- profile
185
+ verbose
186
186
  });
187
187
  return transformedConfig;
188
188
  }
@@ -6,7 +6,7 @@ function applyTransformers(config, transformers, context) {
6
6
  count += 1;
7
7
  return acc;
8
8
  }, config);
9
- if (context.profile) {
9
+ if (context.verbose) {
10
10
  if (count > 0) {
11
11
  console.log(`[webpack-configs] Applied ${count} configuration transformers.`);
12
12
  }
package/dist/dev.d.ts CHANGED
@@ -15,12 +15,12 @@ interface DefineDevConfigOptions {
15
15
  cacheDirectory?: string;
16
16
  moduleRules?: NonNullable<Configuration["module"]>["rules"];
17
17
  plugins?: Configuration["plugins"];
18
- htmlWebpackPlugin?: false | HtmlWebpackPlugin.Options;
18
+ htmlWebpackPlugin?: boolean | HtmlWebpackPlugin.Options;
19
19
  fastRefresh?: boolean | ReactRefreshPluginOptions;
20
20
  cssModules?: boolean;
21
- environmentVariables?: Record<string, string | undefined>;
21
+ environmentVariables?: Record<string, unknown>;
22
22
  transformers?: WebpackConfigTransformer[];
23
- profile?: boolean;
23
+ verbose?: boolean;
24
24
  }
25
25
  declare function defineDevConfig(swcConfig: Config, options?: DefineDevConfigOptions): Configuration;
26
26
 
package/dist/dev.js CHANGED
@@ -1,3 +1,3 @@
1
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-EYIS42GE.js';
1
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-JJEPV2N2.js';
2
2
  import './chunk-P2Z3EEVF.js';
3
- import './chunk-EF2WO5MC.js';
3
+ import './chunk-QJI26K46.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-2Q5IGCCY.js';
2
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-EYIS42GE.js';
1
+ export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-GFNG2PBM.js';
2
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-JJEPV2N2.js';
3
3
  import './chunk-P2Z3EEVF.js';
4
- import './chunk-EF2WO5MC.js';
4
+ import './chunk-QJI26K46.js';
5
5
  export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from './chunk-34O5ZLZ6.js';
6
6
  export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from './chunk-JPURRV2F.js';
@@ -2,7 +2,7 @@ import { Configuration } from 'webpack';
2
2
 
3
3
  interface WebpackConfigTransformerContext {
4
4
  environment: "dev" | "build";
5
- profile: boolean;
5
+ verbose: boolean;
6
6
  }
7
7
  type WebpackConfigTransformer = (config: Configuration, context: WebpackConfigTransformerContext) => Configuration;
8
8
  declare function applyTransformers(config: Configuration, transformers: WebpackConfigTransformer[], context: WebpackConfigTransformerContext): Configuration;
@@ -1 +1 @@
1
- export { applyTransformers } from '../chunk-EF2WO5MC.js';
1
+ export { applyTransformers } from '../chunk-QJI26K46.js';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@workleap/webpack-configs",
3
3
  "author": "Workleap",
4
4
  "description": "Workleap recommended webpack config.",
5
- "version": "1.0.3",
5
+ "version": "1.0.5",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
8
8
  "workleap",
@@ -13,7 +13,8 @@
13
13
  "exports": {
14
14
  ".": {
15
15
  "import": "./dist/index.js",
16
- "types": "./dist/index.d.ts"
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
17
18
  }
18
19
  },
19
20
  "files": [
@@ -56,6 +57,7 @@
56
57
  "@swc/helpers": "0.5.1",
57
58
  "@swc/jest": "0.2.29",
58
59
  "@types/jest": "29.5.4",
60
+ "@types/node": "20.5.7",
59
61
  "browserslist": "4.21.10",
60
62
  "jest": "29.6.4",
61
63
  "postcss": "8.4.29",
@@ -66,9 +68,9 @@
66
68
  "webpack": "5.88.2",
67
69
  "webpack-dev-server": "4.15.1",
68
70
  "@workleap/eslint-plugin": "2.1.0",
71
+ "@workleap/swc-configs": "2.1.1",
69
72
  "@workleap/tsup-configs": "3.0.0",
70
- "@workleap/typescript-configs": "3.0.2",
71
- "@workleap/swc-configs": "2.1.1"
73
+ "@workleap/typescript-configs": "3.0.2"
72
74
  },
73
75
  "publishConfig": {
74
76
  "access": "public",