@vyriy/webpack-config 0.1.18 → 0.1.21

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/README.md CHANGED
@@ -20,7 +20,7 @@ With Yarn:
20
20
  yarn add @vyriy/webpack-config webpack webpack-cli
21
21
  ```
22
22
 
23
- Install `webpack` and `webpack-cli` in the consumer project so Webpack CLI commands are available.
23
+ The `webpack` package is listed in the install command because the shared config is consumed by Webpack at build time. Add `webpack-cli` only when the consumer project runs Webpack through CLI commands.
24
24
 
25
25
  ## Usage
26
26
 
@@ -51,7 +51,7 @@ export default ssr(['@w/api'], {
51
51
 
52
52
  The second parameter is a regular Webpack `output` config passed as-is.
53
53
 
54
- Both generators accept a third parameter with local Webpack overrides that are merged over the shared defaults:
54
+ Both generators accept a third parameter with a local Webpack config transform. The transform receives the shared config and returns the final config, so the consumer can choose where to extend defaults and where to replace them:
55
55
 
56
56
  ```js
57
57
  import { csr } from '@vyriy/webpack-config';
@@ -63,11 +63,35 @@ export default csr(
63
63
  filename: 'index.js',
64
64
  clean: true,
65
65
  },
66
- {
66
+ (config) => ({
67
+ ...config,
67
68
  optimization: {
69
+ ...config.optimization,
68
70
  splitChunks: true,
69
71
  },
72
+ }),
73
+ );
74
+ ```
75
+
76
+ For example, append a local CSR plugin while keeping the shared CSR plugin:
77
+
78
+ ```js
79
+ import { csr } from '@vyriy/webpack-config';
80
+
81
+ export default csr(
82
+ './src/index.tsx',
83
+ {
84
+ path: '/absolute/path/to/dist/client',
85
+ filename: 'index.js',
86
+ clean: true,
70
87
  },
88
+ (config) => ({
89
+ ...config,
90
+ plugins: [
91
+ ...(config.plugins ?? []),
92
+ new LocalPlugin(),
93
+ ],
94
+ }),
71
95
  );
72
96
  ```
73
97
 
@@ -87,9 +111,9 @@ export default config;
87
111
 
88
112
  ## API
89
113
 
90
- - `csr(entry, output, config?)` creates a browser-oriented Webpack config.
91
- - `ssr(entry, output, config?)` creates a node-oriented SSR Webpack config.
92
- - `WebpackConfig`, `WebpackEntry`, and `WebpackOutput` expose the shared config helper types.
114
+ - `csr(entry, output, transform?)` creates a browser-oriented Webpack config.
115
+ - `ssr(entry, output, transform?)` creates a node-oriented SSR Webpack config.
116
+ - `WebpackConfig`, `WebpackConfigTransform`, `WebpackEntry`, and `WebpackOutput` expose the shared config helper types.
93
117
 
94
118
  Shared defaults:
95
119
 
package/csr.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { WebpackConfig, WebpackEntry, WebpackOutput } from './types.js';
2
- export declare const csr: (entry: WebpackEntry, output: WebpackOutput, config?: WebpackConfig) => WebpackConfig;
1
+ import type { WebpackConfig, WebpackConfigTransform, WebpackEntry, WebpackOutput } from './types.js';
2
+ export declare const csr: (entry: WebpackEntry, output: WebpackOutput, transform?: WebpackConfigTransform) => WebpackConfig;
package/csr.js CHANGED
@@ -6,7 +6,7 @@ import { optimization } from './optimization.js';
6
6
  import { performance } from './performance.js';
7
7
  import { resolve } from './resolve.js';
8
8
  import { rules } from './rules.js';
9
- export const csr = (entry, output, config = {}) => {
9
+ export const csr = (entry, output, transform) => {
10
10
  const webpackMode = mode();
11
11
  const isProduction = webpackMode === 'production';
12
12
  const base = {
@@ -22,28 +22,7 @@ export const csr = (entry, output, config = {}) => {
22
22
  optimization: optimization(isProduction),
23
23
  performance,
24
24
  plugins: isProduction ? [new MiniCssExtractPlugin()] : [new ReactRefreshWebpackPlugin()],
25
- resolve: resolve(config.resolve),
26
- };
27
- return {
28
- ...base,
29
- ...config,
30
- output: {
31
- ...base.output,
32
- ...config.output,
33
- },
34
- module: {
35
- ...base.module,
36
- ...config.module,
37
- rules: config.module?.rules ?? base.module?.rules,
38
- },
39
- optimization: base.optimization
40
- ? {
41
- ...base.optimization,
42
- ...config.optimization,
43
- }
44
- : config.optimization,
45
- performance: config.performance ?? performance,
46
- plugins: config.plugins ?? base.plugins,
47
- resolve: resolve(config.resolve),
25
+ resolve: resolve(),
48
26
  };
27
+ return transform ? transform(base) : base;
49
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyriy/webpack-config",
3
- "version": "0.1.18",
3
+ "version": "0.1.21",
4
4
  "description": "Shared Webpack config for Vyriy projects",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -12,8 +12,8 @@
12
12
  "@babel/preset-typescript": "^7.28.5",
13
13
  "@babel/runtime": "^7.29.2",
14
14
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
15
- "@vyriy/env": "0.1.18",
16
- "@vyriy/path": "0.1.18",
15
+ "@vyriy/env": "0.1.21",
16
+ "@vyriy/path": "0.1.21",
17
17
  "babel-loader": "^10.1.1",
18
18
  "css-loader": "^7.1.4",
19
19
  "cssnano": "^8.0.1",
@@ -27,8 +27,7 @@
27
27
  "sass-loader": "^16.0.8",
28
28
  "style-loader": "^4.0.0",
29
29
  "terser-webpack-plugin": "^5.6.0",
30
- "webpack": "^5.106.2",
31
- "webpack-cli": "^7.0.2"
30
+ "webpack": "^5.106.2"
32
31
  },
33
32
  "license": "MIT",
34
33
  "repository": {
package/ssr.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { WebpackConfig, WebpackEntry, WebpackOutput } from './types.js';
2
- export declare const ssr: (entry: WebpackEntry, output: WebpackOutput, config?: WebpackConfig) => WebpackConfig;
1
+ import type { WebpackConfig, WebpackConfigTransform, WebpackEntry, WebpackOutput } from './types.js';
2
+ export declare const ssr: (entry: WebpackEntry, output: WebpackOutput, transform?: WebpackConfigTransform) => WebpackConfig;
package/ssr.js CHANGED
@@ -3,7 +3,7 @@ import { optimization } from './optimization.js';
3
3
  import { performance } from './performance.js';
4
4
  import { resolve } from './resolve.js';
5
5
  import { rules } from './rules.js';
6
- export const ssr = (entry, output, config = {}) => {
6
+ export const ssr = (entry, output, transform) => {
7
7
  const webpackMode = mode();
8
8
  const isProduction = webpackMode === 'production';
9
9
  const base = {
@@ -17,28 +17,7 @@ export const ssr = (entry, output, config = {}) => {
17
17
  },
18
18
  optimization: optimization(isProduction),
19
19
  performance,
20
- resolve: resolve(config.resolve),
21
- };
22
- return {
23
- ...base,
24
- ...config,
25
- output: {
26
- ...base.output,
27
- ...config.output,
28
- library: config.output?.library ?? base.output?.library,
29
- },
30
- module: {
31
- ...base.module,
32
- ...config.module,
33
- rules: config.module?.rules ?? base.module?.rules,
34
- },
35
- optimization: base.optimization
36
- ? {
37
- ...base.optimization,
38
- ...config.optimization,
39
- }
40
- : config.optimization,
41
- performance: config.performance ?? performance,
42
- resolve: resolve(config.resolve),
20
+ resolve: resolve(),
43
21
  };
22
+ return transform ? transform(base) : base;
44
23
  };
package/types.d.ts CHANGED
@@ -2,3 +2,4 @@ import type { Configuration } from 'webpack';
2
2
  export type WebpackConfig = Configuration;
3
3
  export type WebpackEntry = WebpackConfig['entry'];
4
4
  export type WebpackOutput = WebpackConfig['output'];
5
+ export type WebpackConfigTransform = (config: WebpackConfig) => WebpackConfig;