@vyriy/webpack-config 0.4.8 → 0.4.10
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 +3 -2
- package/csr.js +7 -2
- package/dev-server.d.ts +7 -0
- package/dev-server.js +19 -0
- package/package.json +14 -4
- package/rules.d.ts +2 -2
- package/rules.js +4 -1
package/README.md
CHANGED
|
@@ -147,7 +147,8 @@ Shared defaults:
|
|
|
147
147
|
CSR defaults:
|
|
148
148
|
|
|
149
149
|
- loaders and Babel extensions are resolved from this package for workspace and package-manager isolation
|
|
150
|
-
-
|
|
150
|
+
- webpack-dev-server uses shared CORS headers for local cross-origin bundle consumption
|
|
151
|
+
- CSS is extracted with `MiniCssExtractPlugin` in production and development
|
|
151
152
|
- development builds enable React refresh with `ReactRefreshWebpackPlugin`
|
|
152
153
|
|
|
153
154
|
HTML plugin defaults:
|
|
@@ -186,6 +187,6 @@ const styles = document.createElement('style');
|
|
|
186
187
|
styles.textContent = css;
|
|
187
188
|
```
|
|
188
189
|
|
|
189
|
-
This is useful for custom elements that place styles inside a Shadow DOM.
|
|
190
|
+
This is useful for custom elements that place styles inside a Shadow DOM. CSR builds extract ordinary stylesheet imports by default, so custom elements can also use a linked stylesheet without local rule replacement. Webpack dev server can serve the extracted CSS from memory, while production emits the same kind of CSS asset to disk.
|
|
190
191
|
|
|
191
192
|
See the article with a complete browser and SSR bundling walkthrough: <https://vyriy.dev/examples/vyriy-webpack-config/>.
|
package/csr.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
|
2
2
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
3
3
|
import { path } from '@vyriy/path';
|
|
4
|
+
import { devServer } from './dev-server.js';
|
|
4
5
|
import { mode } from './mode.js';
|
|
5
6
|
import { optimization } from './optimization.js';
|
|
6
7
|
import { performance } from './performance.js';
|
|
@@ -12,16 +13,20 @@ export const csr = (entry, output, transform) => {
|
|
|
12
13
|
const base = {
|
|
13
14
|
context: path(),
|
|
14
15
|
devtool: false,
|
|
16
|
+
devServer: devServer(),
|
|
15
17
|
mode: webpackMode,
|
|
16
18
|
target: isProduction ? 'browserslist' : 'web',
|
|
17
19
|
entry,
|
|
18
20
|
output,
|
|
19
21
|
module: {
|
|
20
|
-
rules: rules(false, isProduction),
|
|
22
|
+
rules: rules(false, isProduction, 'extract'),
|
|
21
23
|
},
|
|
22
24
|
optimization: optimization(isProduction),
|
|
23
25
|
performance,
|
|
24
|
-
plugins:
|
|
26
|
+
plugins: [
|
|
27
|
+
new MiniCssExtractPlugin(),
|
|
28
|
+
...(isProduction ? [] : [new ReactRefreshWebpackPlugin()]),
|
|
29
|
+
],
|
|
25
30
|
resolve: resolve(),
|
|
26
31
|
};
|
|
27
32
|
return transform ? transform(base) : base;
|
package/dev-server.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
|
|
2
|
+
export declare const devServerCorsHeaders: {
|
|
3
|
+
readonly 'Access-Control-Allow-Headers': "*";
|
|
4
|
+
readonly 'Access-Control-Allow-Methods': "GET, HEAD, OPTIONS";
|
|
5
|
+
readonly 'Access-Control-Allow-Origin': "*";
|
|
6
|
+
};
|
|
7
|
+
export declare const devServer: (options?: DevServerConfiguration) => DevServerConfiguration;
|
package/dev-server.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const devServerCorsHeaders = {
|
|
2
|
+
'Access-Control-Allow-Headers': '*',
|
|
3
|
+
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
|
|
4
|
+
'Access-Control-Allow-Origin': '*',
|
|
5
|
+
};
|
|
6
|
+
const isHeadersRecord = (headers) => {
|
|
7
|
+
return Boolean(headers) && !Array.isArray(headers) && typeof headers === 'object';
|
|
8
|
+
};
|
|
9
|
+
export const devServer = (options = {}) => {
|
|
10
|
+
return {
|
|
11
|
+
...options,
|
|
12
|
+
headers: isHeadersRecord(options.headers)
|
|
13
|
+
? {
|
|
14
|
+
...devServerCorsHeaders,
|
|
15
|
+
...options.headers,
|
|
16
|
+
}
|
|
17
|
+
: (options.headers ?? devServerCorsHeaders),
|
|
18
|
+
};
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vyriy/webpack-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"description": "Shared Webpack config for Vyriy projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,6 +29,16 @@
|
|
|
29
29
|
"import": "./csr.js",
|
|
30
30
|
"default": "./csr.js"
|
|
31
31
|
},
|
|
32
|
+
"./dev-server": {
|
|
33
|
+
"types": "./dev-server.d.ts",
|
|
34
|
+
"import": "./dev-server.js",
|
|
35
|
+
"default": "./dev-server.js"
|
|
36
|
+
},
|
|
37
|
+
"./dev-server.js": {
|
|
38
|
+
"types": "./dev-server.d.ts",
|
|
39
|
+
"import": "./dev-server.js",
|
|
40
|
+
"default": "./dev-server.js"
|
|
41
|
+
},
|
|
32
42
|
"./external": {
|
|
33
43
|
"types": "./external.d.ts",
|
|
34
44
|
"import": "./external.js",
|
|
@@ -149,9 +159,9 @@
|
|
|
149
159
|
"@babel/register": "^7.29.7",
|
|
150
160
|
"@babel/runtime": "^7.29.7",
|
|
151
161
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
|
|
152
|
-
"@vyriy/env": "0.4.
|
|
153
|
-
"@vyriy/html": "0.4.
|
|
154
|
-
"@vyriy/path": "0.4.
|
|
162
|
+
"@vyriy/env": "0.4.10",
|
|
163
|
+
"@vyriy/html": "0.4.10",
|
|
164
|
+
"@vyriy/path": "0.4.10",
|
|
155
165
|
"babel-loader": "^10.1.1",
|
|
156
166
|
"css-loader": "^7.1.4",
|
|
157
167
|
"cssnano": "^8.0.1",
|
package/rules.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RuleSetRule } from 'webpack';
|
|
2
|
-
import type { WebpackStyleRuleOptions } from './types.js';
|
|
2
|
+
import type { WebpackStyleMode, WebpackStyleRuleOptions } from './types.js';
|
|
3
3
|
export declare const SCRIPT_TEST: RegExp;
|
|
4
4
|
export declare const STYLE_TEST: RegExp;
|
|
5
5
|
export declare const style: ({ mode }?: WebpackStyleRuleOptions) => RuleSetRule;
|
|
6
|
-
export declare const rules: (isSsr?: boolean, isProduction?: boolean) => RuleSetRule[];
|
|
6
|
+
export declare const rules: (isSsr?: boolean, isProduction?: boolean, styleMode?: WebpackStyleMode) => RuleSetRule[];
|
package/rules.js
CHANGED
|
@@ -49,11 +49,14 @@ export const style = ({ mode = 'extract' } = {}) => {
|
|
|
49
49
|
],
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
|
-
export const rules = (isSsr = false, isProduction = true) => {
|
|
52
|
+
export const rules = (isSsr = false, isProduction = true, styleMode) => {
|
|
53
53
|
let mode;
|
|
54
54
|
if (isSsr) {
|
|
55
55
|
mode = 'ignore';
|
|
56
56
|
}
|
|
57
|
+
else if (styleMode) {
|
|
58
|
+
mode = styleMode;
|
|
59
|
+
}
|
|
57
60
|
else if (isProduction) {
|
|
58
61
|
mode = 'extract';
|
|
59
62
|
}
|