@next-core/build-next-bricks 1.1.2 → 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 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
- svgAsAsset?: boolean;
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.1.2",
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": "3e4c6996c85fb0bb14330cd1d128dd8ff690bf5e"
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,54 +241,32 @@ export default async function build(config) {
240
241
  rootMode: "upward",
241
242
  },
242
243
  },
243
- config.svgAsAsset
244
- ? {
245
- // Images
246
- test: /\.(png|svg|jpg|jpeg|gif)$/i,
247
- type: "asset/resource",
248
- generator: {
249
- filename:
250
- config.imageAssetFilename ?? "images/[hash][ext][query]",
251
- },
252
- }
253
- : {
254
- test: /\.svg$/i,
255
- issuer(input) {
256
- // The issuer is null (or an empty string) for dynamic import
257
- return !input || /\.[jt]sx?$/.test(input);
258
- },
259
- use: [
260
- {
261
- loader: "babel-loader",
262
- options: {
263
- rootMode: "upward",
264
- },
265
- },
244
+ {
245
+ // Images
246
+ test: new RegExp(
247
+ `\\.(?:${[
248
+ "png",
249
+ "jpg",
250
+ "jpeg",
251
+ "gif",
252
+ ...(config.svgRules ? [] : ["svg"]),
253
+ ].join("|")})$`,
254
+ "i"
255
+ ),
256
+ type: "asset/resource",
257
+ generator: {
258
+ filename: config.imageAssetFilename ?? "images/[hash][ext][query]",
259
+ },
260
+ },
261
+ ...(config.svgRules ??
262
+ (config.svgAsReactComponent
263
+ ? [
266
264
  {
267
- loader: "@svgr/webpack",
268
- options: {
269
- babel: false,
270
- icon: true,
271
- svgoConfig: {
272
- plugins: [
273
- {
274
- name: "preset-default",
275
- params: {
276
- overrides: {
277
- // Keep `viewbox`
278
- removeViewBox: false,
279
- convertColors: {
280
- currentColor: true,
281
- },
282
- },
283
- },
284
- },
285
- ],
286
- },
287
- },
265
+ test: /\.svg$/i,
266
+ use: getSvgrLoaders(false),
288
267
  },
289
- ],
290
- },
268
+ ]
269
+ : [])),
291
270
  {
292
271
  // Fonts
293
272
  test: /\.(woff|woff2|eot|ttf|otf)$/i,
@@ -296,12 +275,12 @@ export default async function build(config) {
296
275
  filename: "fonts/[hash][ext][query]",
297
276
  },
298
277
  },
299
- ...(config.moduleRules || []),
278
+ ...(config.moduleRules ?? []),
300
279
  ],
301
280
  },
302
281
  devtool: false,
303
282
  optimization:
304
- config.optimization ||
283
+ config.optimization ??
305
284
  (isBricks
306
285
  ? {
307
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
@@ -1,3 +1,4 @@
1
1
  import build from "./build.js";
2
+ import getSvgrLoaders from "./getSvgrLoaders.js";
2
3
 
3
- export { build };
4
+ export { build, getSvgrLoaders };