@workleap/webpack-configs 0.0.1 → 1.0.0

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 ADDED
@@ -0,0 +1,13 @@
1
+ # @workleap/webpack-configs
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#98](https://github.com/gsoft-inc/wl-web-configs/pull/98) [`56ca32e`](https://github.com/gsoft-inc/wl-web-configs/commit/56ca32ee3194c51210aacc5189f3ebbec5a4a7b6) Thanks [@patricklafrance](https://github.com/patricklafrance)! - New start, every package has a major version bump
8
+
9
+ ## 0.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#92](https://github.com/gsoft-inc/wl-web-configs/pull/92) [`66e8f10`](https://github.com/gsoft-inc/wl-web-configs/commit/66e8f1033a987523c65fe9e61f53dac6d2e38777) Thanks [@ofrogon](https://github.com/ofrogon)! - Migrate project from GitHub organization
package/README.md CHANGED
@@ -1,7 +1,22 @@
1
1
  # webpack-configs
2
2
 
3
- ## Gotchas to remember
3
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](../../LICENSE)
4
+ [![npm version](https://img.shields.io/npm/v/@workleap/webpack-configs)](https://www.npmjs.com/package/@workleap/webpack-configs)
4
5
 
5
- ### Add the @swc/helpers packages to all importer projects having JSX code
6
+ ## Usage
7
+
8
+ View the [user's documentation](https://gsoft-inc.github.io/wl-web-configs/).
9
+
10
+ ## 🤝 Contributing
11
+
12
+ View the [contributor's documentation](../../CONTRIBUTING.md).
13
+
14
+ ### Notes
15
+
16
+ #### Add the @swc/helpers packages to all monorepo imported projects having JSX code
6
17
 
7
18
  To work properly, all projects having React/JSX code that are referenced by the host project must also install `@swc/helpers` as a `devDependency`.
19
+
20
+ ## License
21
+
22
+ Copyright © 2023, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/workleap-license/blob/master/LICENSE.
package/dist/build.d.ts CHANGED
@@ -13,12 +13,12 @@ interface DefineBuildConfigOptions {
13
13
  publicPath?: string;
14
14
  moduleRules?: NonNullable<Configuration["module"]>["rules"];
15
15
  plugins?: Configuration["plugins"];
16
- htmlWebpackPlugin?: HtmlWebpackPlugin.Options;
17
- miniCssExtractPlugin?: MiniCssExtractPluginOptions;
16
+ htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
17
+ miniCssExtractPluginOptions?: MiniCssExtractPluginOptions;
18
18
  minify?: boolean;
19
19
  cssModules?: boolean;
20
- postcssConfigFilePath?: string;
21
20
  swcConfig: Config;
21
+ environmentVariables?: Record<string, string | undefined>;
22
22
  transformers?: WebpackConfigTransformer[];
23
23
  }
24
24
  declare function defineBuildConfig(options: DefineBuildConfigOptions): Configuration;
package/dist/build.js CHANGED
@@ -1,2 +1,2 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-6VLNR4XR.js';
1
+ export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-QSPIAXE3.js';
2
2
  import './chunk-URL2KA63.js';
@@ -107,7 +107,7 @@ function addBeforeModuleRule(config, matcher, newModuleRules) {
107
107
  match.parent.splice(match.index, 0, ...newModuleRules);
108
108
  } else {
109
109
  const matcherInfo = matcher.info;
110
- console.log(`[web-configs] Couldn't add the new module rules because no match has been found.
110
+ throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.
111
111
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
112
112
  }
113
113
  }
@@ -117,7 +117,7 @@ function addAfterModuleRule(config, matcher, newModuleRules) {
117
117
  match.parent.splice(match.index + 1, 0, ...newModuleRules);
118
118
  } else {
119
119
  const matcherInfo = matcher.info;
120
- console.log(`[web-configs] Couldn't add the new module rules because no match has been found.
120
+ throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.
121
121
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
122
122
  }
123
123
  }
@@ -127,7 +127,7 @@ function replaceModuleRule(config, matcher, newModuleRule) {
127
127
  match.parent[match.index] = newModuleRule;
128
128
  } else {
129
129
  const matcherInfo = matcher.info;
130
- console.log(`[web-configs] Couldn't replace the module rule because no match has been found.
130
+ throw new Error(`[webpack-configs] Couldn't replace the module rule because no match has been found.
131
131
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
132
132
  }
133
133
  }
@@ -146,7 +146,7 @@ function removeModuleRules(config, matcher) {
146
146
  });
147
147
  } else {
148
148
  const matcherInfo = matcher.info;
149
- console.log(`[web-configs] Didn't remove any module rules because no match has been found.
149
+ throw new Error(`[webpack-configs] Didn't remove any module rules because no match has been found.
150
150
  [webpack-configs] Matcher: "${matcherInfo}"`);
151
151
  }
152
152
  }
@@ -22,7 +22,7 @@ function findPlugin(config, matcher) {
22
22
  if (matches.length > 1) {
23
23
  const matcherInfo = matcher.info;
24
24
  throw new Error(`[webpack-configs] Found more than 1 matching plugin.
25
- [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"
25
+ [webp-configs] Matcher: "${JSON.stringify(matcherInfo)}"
26
26
  [webpack-configs] Matches: "${JSON.stringify(matches.map((x) => x.plugin))}"`);
27
27
  }
28
28
  return matches[0];
@@ -33,7 +33,7 @@ function replacePlugin(config, matcher, newPlugin) {
33
33
  config.plugins[match.index] = newPlugin;
34
34
  } else {
35
35
  const matcherInfo = matcher.info;
36
- console.log(`[web-configs] Couldn't replace the plugin because no match has been found.
36
+ throw new Error(`[webpack-configs] Couldn't replace the plugin because no match has been found.
37
37
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
38
38
  }
39
39
  }
@@ -43,7 +43,7 @@ function addBeforePlugin(config, matcher, newPlugins) {
43
43
  config.plugins?.splice(match.index, 0, ...newPlugins);
44
44
  } else {
45
45
  const matcherInfo = matcher.info;
46
- console.log(`[web-configs] Couldn't add the new plugins because no match has been found.
46
+ throw new Error(`[webpack-configs] Couldn't add the new plugins because no match has been found.
47
47
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
48
48
  }
49
49
  }
@@ -53,7 +53,7 @@ function addAfterPlugin(config, matcher, newPlugins) {
53
53
  config.plugins?.splice(match.index + 1, 0, ...newPlugins);
54
54
  } else {
55
55
  const matcherInfo = matcher.info;
56
- console.log(`[web-configs] Couldn't add the new plugins because no match has been found.
56
+ throw new Error(`[webpack-configs] Couldn't add the new plugins because no match has been found.
57
57
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
58
58
  }
59
59
  }
@@ -63,7 +63,7 @@ function removePlugin(config, matcher) {
63
63
  const countAfter = config.plugins?.length ?? 0;
64
64
  if (countBefore === countAfter) {
65
65
  const matcherInfo = matcher.info;
66
- console.log(`[web-configs] Didn't remove any plugin because no match has been found.
66
+ throw new Error(`[webpack-configs] Didn't remove any plugin because no match has been found.
67
67
  [webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
68
68
  }
69
69
  }
@@ -5,8 +5,10 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
5
5
  import { createRequire } from 'node:module';
6
6
  import path from 'path';
7
7
  import { fileURLToPath } from 'url';
8
+ import webpack from 'webpack';
8
9
  import 'webpack-dev-server';
9
10
 
11
+ var DefinePlugin = webpack.DefinePlugin;
10
12
  var require2 = createRequire(import.meta.url);
11
13
  function defineDevHtmlWebpackPluginConfig(options = {}) {
12
14
  const {
@@ -23,11 +25,11 @@ function defineFastRefreshPluginConfig(options = {}) {
23
25
  }
24
26
  function preflight(options) {
25
27
  if (!require2.resolve("webpack-dev-server")) {
26
- throw new Error('To use the "dev" config, install https://www.npmjs.com/package/webpack-dev-server as a "devDependency".');
28
+ throw new Error('[webpack-configs] To use the "dev" config, install https://www.npmjs.com/package/webpack-dev-server as a "devDependency".');
27
29
  }
28
30
  if (options.fastRefresh) {
29
31
  if (!require2.resolve("@pmmmwh/react-refresh-webpack-plugin")) {
30
- throw new Error('To use Webpack Fast Refresh, install https://www.npmjs.com/package/@pmmmwh/react-refresh-webpack-plugin as a "devDependency".');
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".');
31
33
  }
32
34
  }
33
35
  }
@@ -51,8 +53,8 @@ function defineDevConfig(options) {
51
53
  htmlWebpackPluginOptions = defineDevHtmlWebpackPluginConfig(),
52
54
  fastRefresh = false,
53
55
  cssModules = false,
54
- postcssConfigFilePath,
55
56
  swcConfig,
57
+ environmentVariables,
56
58
  transformers = []
57
59
  } = options;
58
60
  const config = {
@@ -60,7 +62,9 @@ function defineDevConfig(options) {
60
62
  target: "web",
61
63
  devtool: "eval-cheap-module-source-map",
62
64
  devServer: {
63
- hot: !fastRefresh,
65
+ // According to the Fast Refresh plugin documentation, hot should be "true" to enable Fast Refresh:
66
+ // https://github.com/pmmmwh/react-refresh-webpack-plugin#usage.
67
+ hot: true,
64
68
  https,
65
69
  host,
66
70
  port,
@@ -114,14 +118,7 @@ function defineDevConfig(options) {
114
118
  modules: true
115
119
  } : void 0
116
120
  },
117
- {
118
- loader: require2.resolve("postcss-loader"),
119
- options: postcssConfigFilePath ? {
120
- postcssOptions: {
121
- config: postcssConfigFilePath
122
- }
123
- } : void 0
124
- }
121
+ { loader: require2.resolve("postcss-loader") }
125
122
  ]
126
123
  },
127
124
  {
@@ -140,12 +137,15 @@ function defineDevConfig(options) {
140
137
  },
141
138
  plugins: [
142
139
  new HtmlWebpackPlugin(htmlWebpackPluginOptions),
140
+ new DefinePlugin({
141
+ "process.env": JSON.stringify(environmentVariables)
142
+ }),
143
143
  fastRefresh && new ReactRefreshWebpackPlugin(isObject(fastRefresh) ? fastRefresh : defineFastRefreshPluginConfig()),
144
144
  ...plugins
145
145
  ].filter(Boolean)
146
146
  };
147
147
  const transformedConfig = applyTransformers(config, transformers, {
148
- env: "dev"
148
+ environment: "dev"
149
149
  });
150
150
  return transformedConfig;
151
151
  }
@@ -4,7 +4,9 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
4
  import { createRequire } from 'node:module';
5
5
  import path from 'path';
6
6
  import TerserPlugin from 'terser-webpack-plugin';
7
+ import webpack from 'webpack';
7
8
 
9
+ var DefinePlugin = webpack.DefinePlugin;
8
10
  var require2 = createRequire(import.meta.url);
9
11
  function defineBuildHtmlWebpackPluginConfig(options = {}) {
10
12
  const {
@@ -34,12 +36,12 @@ function defineBuildConfig(options) {
34
36
  publicPath = "http://localhost:8080/",
35
37
  moduleRules = [],
36
38
  plugins = [],
37
- htmlWebpackPlugin = defineBuildHtmlWebpackPluginConfig(),
38
- miniCssExtractPlugin = defineMiniCssExtractPluginConfig(),
39
+ htmlWebpackPluginOptions = defineBuildHtmlWebpackPluginConfig(),
40
+ miniCssExtractPluginOptions = defineMiniCssExtractPluginConfig(),
39
41
  minify = true,
40
42
  cssModules = false,
41
- postcssConfigFilePath,
42
43
  swcConfig,
44
+ environmentVariables,
43
45
  transformers = []
44
46
  } = options;
45
47
  const config = {
@@ -92,14 +94,7 @@ function defineBuildConfig(options) {
92
94
  modules: true
93
95
  } : void 0
94
96
  },
95
- {
96
- loader: require2.resolve("postcss-loader"),
97
- options: postcssConfigFilePath ? {
98
- postcssOptions: {
99
- config: postcssConfigFilePath
100
- }
101
- } : void 0
102
- }
97
+ { loader: require2.resolve("postcss-loader") }
103
98
  ]
104
99
  },
105
100
  {
@@ -117,13 +112,18 @@ function defineBuildConfig(options) {
117
112
  extensions: [".js", ".jsx", ".ts", ".tsx", ".css"]
118
113
  },
119
114
  plugins: [
120
- new HtmlWebpackPlugin(htmlWebpackPlugin),
121
- new MiniCssExtractPlugin(miniCssExtractPlugin),
115
+ new HtmlWebpackPlugin(htmlWebpackPluginOptions),
116
+ new MiniCssExtractPlugin(miniCssExtractPluginOptions),
117
+ new DefinePlugin({
118
+ // Parenthesis around the stringified object are mandatory otherwise it breaks
119
+ // at build time.
120
+ "process.env": `(${JSON.stringify(environmentVariables)})`
121
+ }),
122
122
  ...plugins
123
- ]
123
+ ].filter(Boolean)
124
124
  };
125
125
  const transformedConfig = applyTransformers(config, transformers, {
126
- env: "build"
126
+ environment: "build"
127
127
  });
128
128
  return transformedConfig;
129
129
  }
package/dist/dev.d.ts CHANGED
@@ -18,8 +18,8 @@ interface DefineDevConfigOptions {
18
18
  htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
19
19
  fastRefresh?: boolean | ReactRefreshPluginOptions;
20
20
  cssModules?: boolean;
21
- postcssConfigFilePath?: string;
22
21
  swcConfig: Config;
22
+ environmentVariables?: Record<string, string | undefined>;
23
23
  transformers?: WebpackConfigTransformer[];
24
24
  }
25
25
  declare function defineDevConfig(options: DefineDevConfigOptions): Configuration;
package/dist/dev.js CHANGED
@@ -1,3 +1,3 @@
1
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-LUBW6XFE.js';
1
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-OVSH7SYO.js';
2
2
  import './chunk-P2Z3EEVF.js';
3
3
  import './chunk-URL2KA63.js';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { Configuration as WebpackConfig } from 'webpack';
1
2
  export { DefineBuildConfigOptions, defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './build.js';
2
3
  export { DefineDevConfigOptions, defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './dev.js';
3
4
  export { WebpackConfigTransformer, WebpackConfigTransformerContext } from './transformers/applyTransformers.js';
@@ -6,5 +7,4 @@ export { PluginMatch, PluginMatcher, WebpackPlugin, WithPluginMatcherInfo, addAf
6
7
  import '@swc/core';
7
8
  import 'html-webpack-plugin';
8
9
  import 'mini-css-extract-plugin';
9
- import 'webpack';
10
10
  import '@pmmmwh/react-refresh-webpack-plugin/types/lib/types.d.ts';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-6VLNR4XR.js';
2
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-LUBW6XFE.js';
1
+ export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig } from './chunk-QSPIAXE3.js';
2
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-OVSH7SYO.js';
3
3
  import './chunk-P2Z3EEVF.js';
4
4
  import './chunk-URL2KA63.js';
5
- export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from './chunk-RZJNTAWK.js';
6
- export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from './chunk-ZOH3SP3K.js';
5
+ export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from './chunk-34O5ZLZ6.js';
6
+ export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from './chunk-JPURRV2F.js';
@@ -1,7 +1,7 @@
1
1
  import { Configuration } from 'webpack';
2
2
 
3
3
  interface WebpackConfigTransformerContext {
4
- env: "dev" | "build";
4
+ environment: "dev" | "build";
5
5
  }
6
6
  type WebpackConfigTransformer = (config: Configuration, context: WebpackConfigTransformerContext) => Configuration;
7
7
  declare function applyTransformers(config: Configuration, transformers: WebpackConfigTransformer[], context: WebpackConfigTransformerContext): Configuration;
@@ -1 +1 @@
1
- export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from '../chunk-RZJNTAWK.js';
1
+ export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from '../chunk-34O5ZLZ6.js';
@@ -1 +1 @@
1
- export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from '../chunk-ZOH3SP3K.js';
1
+ export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from '../chunk-JPURRV2F.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": "0.0.1",
5
+ "version": "1.0.0",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
8
8
  "workleap",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "git+https://github.com/workleap/wl-web-configs.git",
27
+ "url": "git+https://github.com/gsoft-inc/wl-web-configs.git",
28
28
  "directory": "packages/webpack-configs"
29
29
  },
30
30
  "dependencies": {
@@ -71,10 +71,10 @@
71
71
  "typescript": "5.0.4",
72
72
  "webpack": "5.86.0",
73
73
  "webpack-dev-server": "4.15.0",
74
- "@workleap/eslint-plugin": "1.8.2",
75
- "@workleap/swc-configs": "1.0.0",
76
- "@workleap/tsup-configs": "2.0.0",
77
- "@workleap/typescript-configs": "2.3.2"
74
+ "@workleap/eslint-plugin": "2.0.0",
75
+ "@workleap/swc-configs": "2.0.0",
76
+ "@workleap/tsup-configs": "3.0.0",
77
+ "@workleap/typescript-configs": "3.0.0"
78
78
  },
79
79
  "publishConfig": {
80
80
  "access": "public",