@next-core/build-next-bricks 1.1.1 → 1.2.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/index.d.ts +9 -1
- package/package.json +2 -2
- package/src/build.js +22 -41
- package/src/getSvgrLoaders.js +34 -0
- package/src/index.js +2 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Compiler, Configuration, RuleSetRule, container } from "webpack";
|
|
2
2
|
|
|
3
3
|
export declare function build(config: BuildNextBricksConfig): Compiler;
|
|
4
|
+
export declare function getSvgrLoaders(options: {
|
|
5
|
+
/** Set it to true for font icons */
|
|
6
|
+
convertCurrentColor?: boolean;
|
|
7
|
+
}): RuleSetRule["use"];
|
|
4
8
|
|
|
5
9
|
// Types of `SharedConfig` and `SharedObject` are copied from webpack.
|
|
6
10
|
|
|
@@ -66,7 +70,11 @@ export interface BuildNextBricksConfig {
|
|
|
66
70
|
mode?: "development" | "production";
|
|
67
71
|
entry?: Record<string, string>;
|
|
68
72
|
extractCss?: boolean;
|
|
69
|
-
|
|
73
|
+
/** Treat svg as React component instead of asset */
|
|
74
|
+
svgAsReactComponent?: boolean;
|
|
75
|
+
/** Customize rules for svg */
|
|
76
|
+
svgRules?: RuleSetRule[];
|
|
77
|
+
/** By default the image assets are named `images/[hash][ext][query]` */
|
|
70
78
|
imageAssetFilename?: string | ((pathData: any, assetInfo: any) => string);
|
|
71
79
|
plugins?: Configuration["plugins"];
|
|
72
80
|
moduleRules?: RuleSetRule[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-next-bricks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Build next bricks",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/master/packages/build-next-bricks",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"typescript": "^5.0.2",
|
|
47
47
|
"webpack": "^5.76.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "5f7e81c60f23e6b1ad116bd07e943ff743900766"
|
|
50
50
|
}
|
package/src/build.js
CHANGED
|
@@ -8,6 +8,7 @@ import cssnano from "cssnano";
|
|
|
8
8
|
import cssnanoPresetLite from "cssnano-preset-lite";
|
|
9
9
|
import EmitBricksJsonPlugin from "./EmitBricksJsonPlugin.js";
|
|
10
10
|
import getCamelPackageName from "./getCamelPackageName.js";
|
|
11
|
+
import getSvgrLoaders from "./getSvgrLoaders.js";
|
|
11
12
|
|
|
12
13
|
const require = createRequire(import.meta.url);
|
|
13
14
|
|
|
@@ -240,52 +241,32 @@ export default async function build(config) {
|
|
|
240
241
|
rootMode: "upward",
|
|
241
242
|
},
|
|
242
243
|
},
|
|
243
|
-
{
|
|
244
|
-
test: /\.svg$/i,
|
|
245
|
-
issuer(input) {
|
|
246
|
-
// The issuer is null (or an empty string) for dynamic import
|
|
247
|
-
return !config.svgAsAsset && (!input || /\.[jt]sx?$/.test(input));
|
|
248
|
-
},
|
|
249
|
-
use: [
|
|
250
|
-
{
|
|
251
|
-
loader: "babel-loader",
|
|
252
|
-
options: {
|
|
253
|
-
rootMode: "upward",
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
loader: "@svgr/webpack",
|
|
258
|
-
options: {
|
|
259
|
-
babel: false,
|
|
260
|
-
icon: true,
|
|
261
|
-
svgoConfig: {
|
|
262
|
-
plugins: [
|
|
263
|
-
{
|
|
264
|
-
name: "preset-default",
|
|
265
|
-
params: {
|
|
266
|
-
overrides: {
|
|
267
|
-
// Keep `viewbox`
|
|
268
|
-
removeViewBox: false,
|
|
269
|
-
convertColors: {
|
|
270
|
-
currentColor: true,
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
],
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
],
|
|
280
|
-
},
|
|
281
244
|
{
|
|
282
245
|
// Images
|
|
283
|
-
test:
|
|
246
|
+
test: new RegExp(
|
|
247
|
+
`\\.(?:${[
|
|
248
|
+
"png",
|
|
249
|
+
"jpg",
|
|
250
|
+
"jpeg",
|
|
251
|
+
"gif",
|
|
252
|
+
...(config.svgRules ? [] : ["svg"]),
|
|
253
|
+
].join("|")})$`,
|
|
254
|
+
"i"
|
|
255
|
+
),
|
|
284
256
|
type: "asset/resource",
|
|
285
257
|
generator: {
|
|
286
258
|
filename: config.imageAssetFilename ?? "images/[hash][ext][query]",
|
|
287
259
|
},
|
|
288
260
|
},
|
|
261
|
+
...(config.svgRules ??
|
|
262
|
+
(config.svgAsReactComponent
|
|
263
|
+
? [
|
|
264
|
+
{
|
|
265
|
+
test: /\.svg$/i,
|
|
266
|
+
use: getSvgrLoaders(false),
|
|
267
|
+
},
|
|
268
|
+
]
|
|
269
|
+
: [])),
|
|
289
270
|
{
|
|
290
271
|
// Fonts
|
|
291
272
|
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
@@ -294,12 +275,12 @@ export default async function build(config) {
|
|
|
294
275
|
filename: "fonts/[hash][ext][query]",
|
|
295
276
|
},
|
|
296
277
|
},
|
|
297
|
-
...(config.moduleRules
|
|
278
|
+
...(config.moduleRules ?? []),
|
|
298
279
|
],
|
|
299
280
|
},
|
|
300
281
|
devtool: false,
|
|
301
282
|
optimization:
|
|
302
|
-
config.optimization
|
|
283
|
+
config.optimization ??
|
|
303
284
|
(isBricks
|
|
304
285
|
? {
|
|
305
286
|
splitChunks: {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export default function getSvgrLoaders(options = {}) {
|
|
2
|
+
return [
|
|
3
|
+
{
|
|
4
|
+
loader: "babel-loader",
|
|
5
|
+
options: {
|
|
6
|
+
rootMode: "upward",
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
loader: "@svgr/webpack",
|
|
11
|
+
options: {
|
|
12
|
+
babel: false,
|
|
13
|
+
icon: true,
|
|
14
|
+
svgoConfig: {
|
|
15
|
+
plugins: [
|
|
16
|
+
{
|
|
17
|
+
name: "preset-default",
|
|
18
|
+
params: {
|
|
19
|
+
overrides: {
|
|
20
|
+
// Keep `viewbox`
|
|
21
|
+
removeViewBox: false,
|
|
22
|
+
|
|
23
|
+
convertColors: {
|
|
24
|
+
currentColor: options.convertCurrentColor ?? false,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
}
|
package/src/index.js
CHANGED