@workleap/webpack-configs 1.0.1 → 1.0.2

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,11 @@
1
1
  # @workleap/webpack-configs
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#120](https://github.com/gsoft-inc/wl-web-configs/pull/120) [`0e66000`](https://github.com/gsoft-inc/wl-web-configs/commit/0e66000b2028cad9c606d3523e3bcf540e6350e2) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Updated configs
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
package/dist/build.d.ts CHANGED
@@ -11,14 +11,17 @@ interface DefineBuildConfigOptions {
11
11
  entry?: string;
12
12
  outputPath?: string;
13
13
  publicPath?: string;
14
+ cache?: boolean;
15
+ cacheDirectory?: string;
14
16
  moduleRules?: NonNullable<Configuration["module"]>["rules"];
15
17
  plugins?: Configuration["plugins"];
16
- htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
18
+ htmlWebpackPlugin?: false | HtmlWebpackPlugin.Options;
17
19
  miniCssExtractPluginOptions?: MiniCssExtractPluginOptions;
18
20
  minify?: boolean;
19
21
  cssModules?: boolean;
20
22
  environmentVariables?: Record<string, string | undefined>;
21
23
  transformers?: WebpackConfigTransformer[];
24
+ profile?: boolean;
22
25
  }
23
26
  declare function defineBuildConfig(swcConfig: Config, options?: DefineBuildConfigOptions): Configuration;
24
27
 
package/dist/build.js CHANGED
@@ -1,2 +1,2 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-Z4O6KPRR.js';
1
+ export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-IGATFK3O.js';
2
2
  import './chunk-URL2KA63.js';
@@ -2,7 +2,8 @@ import { applyTransformers } from './chunk-URL2KA63.js';
2
2
  import HtmlWebpackPlugin from 'html-webpack-plugin';
3
3
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
4
  import { createRequire } from 'node:module';
5
- import path from 'path';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
6
7
  import TerserPlugin from 'terser-webpack-plugin';
7
8
  import webpack from 'webpack';
8
9
 
@@ -34,14 +35,17 @@ function defineBuildConfig(swcConfig, options = {}) {
34
35
  outputPath = path.resolve("dist"),
35
36
  // The trailing / is very important, otherwise paths will not be resolved correctly.
36
37
  publicPath = "http://localhost:8080/",
38
+ cache = true,
39
+ cacheDirectory = path.resolve("node_modules/.cache/webpack"),
37
40
  moduleRules = [],
38
41
  plugins = [],
39
- htmlWebpackPluginOptions = defineBuildHtmlWebpackPluginConfig(),
42
+ htmlWebpackPlugin = defineBuildHtmlWebpackPluginConfig(),
40
43
  miniCssExtractPluginOptions = defineMiniCssExtractPluginConfig(),
41
44
  minify = true,
42
45
  cssModules = false,
43
46
  environmentVariables,
44
- transformers = []
47
+ transformers = [],
48
+ profile = false
45
49
  } = options;
46
50
  const config = {
47
51
  mode: "production",
@@ -53,6 +57,34 @@ function defineBuildConfig(swcConfig, options = {}) {
53
57
  publicPath,
54
58
  clean: true
55
59
  },
60
+ cache: cache && {
61
+ type: "filesystem",
62
+ allowCollectingMemory: false,
63
+ buildDependencies: {
64
+ config: [fileURLToPath(import.meta.url)]
65
+ },
66
+ cacheDirectory
67
+ },
68
+ // Fixes caching for environmental variables using the DefinePlugin by forcing
69
+ // webpack caching to prioritize hashes over timestamps.
70
+ snapshot: {
71
+ buildDependencies: {
72
+ hash: true,
73
+ timestamp: true
74
+ },
75
+ module: {
76
+ hash: true,
77
+ timestamp: true
78
+ },
79
+ resolve: {
80
+ hash: true,
81
+ timestamp: true
82
+ },
83
+ resolveBuildDependencies: {
84
+ hash: true,
85
+ timestamp: true
86
+ }
87
+ },
56
88
  optimization: minify ? {
57
89
  minimize: true,
58
90
  minimizer: [
@@ -65,6 +97,11 @@ function defineBuildConfig(swcConfig, options = {}) {
65
97
  })
66
98
  ]
67
99
  } : void 0,
100
+ infrastructureLogging: profile ? {
101
+ appendOnly: true,
102
+ level: "verbose",
103
+ debug: /PackFileCache/
104
+ } : void 0,
68
105
  module: {
69
106
  rules: [
70
107
  {
@@ -108,15 +145,19 @@ function defineBuildConfig(swcConfig, options = {}) {
108
145
  ]
109
146
  },
110
147
  resolve: {
111
- extensions: [".js", ".jsx", ".ts", ".tsx", ".css"]
148
+ extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
149
+ alias: {
150
+ // Fixes Module not found: Error: Can't resolve '@swc/helpers/_/_class_private_field_init'.
151
+ // View https://github.com/vercel/next.js/pull/38174 for more information and https://github.com/vercel/next.js/issues/48593.
152
+ "@swc/helpers": path.dirname(require2.resolve("@swc/helpers/package.json"))
153
+ }
112
154
  },
113
155
  plugins: [
114
- new HtmlWebpackPlugin(htmlWebpackPluginOptions),
156
+ htmlWebpackPlugin && new HtmlWebpackPlugin(htmlWebpackPlugin),
115
157
  new MiniCssExtractPlugin(miniCssExtractPluginOptions),
116
158
  new DefinePlugin({
117
- // Parenthesis around the stringified object are mandatory otherwise it breaks
118
- // at build time.
119
- "process.env": `(${JSON.stringify(environmentVariables)})`
159
+ // Webpack automatically stringify object literals.
160
+ "process.env": environmentVariables
120
161
  }),
121
162
  ...plugins
122
163
  ].filter(Boolean)
@@ -3,8 +3,8 @@ import { applyTransformers } from './chunk-URL2KA63.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';
6
- import path from 'path';
7
- import { fileURLToPath } from 'url';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
8
  import webpack from 'webpack';
9
9
  import 'webpack-dev-server';
10
10
 
@@ -33,9 +33,9 @@ function preflight(options) {
33
33
  }
34
34
  }
35
35
  }
36
- function tryEnableSwcReactRefresh(config) {
36
+ function trySetSwcFastRefresh(config, enabled) {
37
37
  if (config?.jsc?.transform?.react) {
38
- config.jsc.transform.react.refresh = true;
38
+ config.jsc.transform.react.refresh = enabled;
39
39
  }
40
40
  return config;
41
41
  }
@@ -50,11 +50,12 @@ function defineDevConfig(swcConfig, options = {}) {
50
50
  cacheDirectory = path.resolve("node_modules/.cache/webpack"),
51
51
  moduleRules = [],
52
52
  plugins = [],
53
- htmlWebpackPluginOptions = defineDevHtmlWebpackPluginConfig(),
54
- fastRefresh = false,
53
+ htmlWebpackPlugin = defineDevHtmlWebpackPluginConfig(),
54
+ fastRefresh = true,
55
55
  cssModules = false,
56
56
  environmentVariables,
57
- transformers = []
57
+ transformers = [],
58
+ profile = false
58
59
  } = options;
59
60
  const config = {
60
61
  mode: "development",
@@ -74,14 +75,35 @@ function defineDevConfig(swcConfig, options = {}) {
74
75
  // The trailing / is very important, otherwise paths will not be resolved correctly.
75
76
  publicPath: `${https ? "https" : "http"}://${host}:${port}/`
76
77
  },
77
- cache: cache !== false && {
78
+ cache: cache && {
78
79
  type: "filesystem",
79
80
  allowCollectingMemory: true,
81
+ maxMemoryGenerations: 1,
80
82
  buildDependencies: {
81
83
  config: [fileURLToPath(import.meta.url)]
82
84
  },
83
85
  cacheDirectory
84
86
  },
87
+ // Fixes caching for environmental variables using the DefinePlugin by forcing
88
+ // webpack caching to prioritize hashes over timestamps.
89
+ snapshot: {
90
+ buildDependencies: {
91
+ hash: true,
92
+ timestamp: true
93
+ },
94
+ module: {
95
+ hash: true,
96
+ timestamp: true
97
+ },
98
+ resolve: {
99
+ hash: true,
100
+ timestamp: true
101
+ },
102
+ resolveBuildDependencies: {
103
+ hash: true,
104
+ timestamp: true
105
+ }
106
+ },
85
107
  optimization: {
86
108
  // See: https://webpack.js.org/guides/build-performance/#avoid-extra-optimization-steps
87
109
  runtimeChunk: true,
@@ -89,13 +111,18 @@ function defineDevConfig(swcConfig, options = {}) {
89
111
  removeEmptyChunks: false,
90
112
  splitChunks: false
91
113
  },
114
+ infrastructureLogging: profile ? {
115
+ appendOnly: true,
116
+ level: "verbose",
117
+ debug: /PackFileCache/
118
+ } : void 0,
92
119
  module: {
93
120
  rules: [
94
121
  {
95
122
  test: /\.(js|jsx|ts|tsx)/i,
96
123
  exclude: /node_modules/,
97
124
  loader: require2.resolve("swc-loader"),
98
- options: fastRefresh ? tryEnableSwcReactRefresh(swcConfig) : swcConfig
125
+ options: trySetSwcFastRefresh(swcConfig, fastRefresh !== false)
99
126
  },
100
127
  {
101
128
  // https://stackoverflow.com/questions/69427025/programmatic-webpack-jest-esm-cant-resolve-module-without-js-file-exten
@@ -132,12 +159,18 @@ function defineDevConfig(swcConfig, options = {}) {
132
159
  ]
133
160
  },
134
161
  resolve: {
135
- extensions: [".js", ".jsx", ".ts", ".tsx", ".css"]
162
+ extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
163
+ alias: {
164
+ // Fixes Module not found: Error: Can't resolve '@swc/helpers/_/_class_private_field_init'.
165
+ // View https://github.com/vercel/next.js/pull/38174 for more information and https://github.com/vercel/next.js/issues/48593.
166
+ "@swc/helpers": path.dirname(require2.resolve("@swc/helpers/package.json"))
167
+ }
136
168
  },
137
169
  plugins: [
138
- new HtmlWebpackPlugin(htmlWebpackPluginOptions),
170
+ htmlWebpackPlugin && new HtmlWebpackPlugin(htmlWebpackPlugin),
139
171
  new DefinePlugin({
140
- "process.env": JSON.stringify(environmentVariables)
172
+ // Webpack automatically stringify object literals.
173
+ "process.env": environmentVariables
141
174
  }),
142
175
  fastRefresh && new ReactRefreshWebpackPlugin(isObject(fastRefresh) ? fastRefresh : defineFastRefreshPluginConfig()),
143
176
  ...plugins
package/dist/dev.d.ts CHANGED
@@ -15,11 +15,12 @@ interface DefineDevConfigOptions {
15
15
  cacheDirectory?: string;
16
16
  moduleRules?: NonNullable<Configuration["module"]>["rules"];
17
17
  plugins?: Configuration["plugins"];
18
- htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
18
+ htmlWebpackPlugin?: false | HtmlWebpackPlugin.Options;
19
19
  fastRefresh?: boolean | ReactRefreshPluginOptions;
20
20
  cssModules?: boolean;
21
21
  environmentVariables?: Record<string, string | undefined>;
22
22
  transformers?: WebpackConfigTransformer[];
23
+ profile?: boolean;
23
24
  }
24
25
  declare function defineDevConfig(swcConfig: Config, options?: DefineDevConfigOptions): Configuration;
25
26
 
package/dist/dev.js CHANGED
@@ -1,3 +1,3 @@
1
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-DSXM2GXS.js';
1
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-SBBLJ5AL.js';
2
2
  import './chunk-P2Z3EEVF.js';
3
3
  import './chunk-URL2KA63.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-Z4O6KPRR.js';
2
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-DSXM2GXS.js';
1
+ export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-IGATFK3O.js';
2
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-SBBLJ5AL.js';
3
3
  import './chunk-P2Z3EEVF.js';
4
4
  import './chunk-URL2KA63.js';
5
5
  export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from './chunk-34O5ZLZ6.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.1",
5
+ "version": "1.0.2",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
8
8
  "workleap",
@@ -65,8 +65,8 @@
65
65
  "typescript": "5.2.2",
66
66
  "webpack": "5.88.2",
67
67
  "webpack-dev-server": "4.15.1",
68
- "@workleap/swc-configs": "2.1.0",
69
68
  "@workleap/eslint-plugin": "2.1.0",
69
+ "@workleap/swc-configs": "2.1.1",
70
70
  "@workleap/tsup-configs": "3.0.0",
71
71
  "@workleap/typescript-configs": "3.0.2"
72
72
  },