Skip to content

Commit

Permalink
feat(plugin-svgr): use Rslib to bundle (#3698)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 12, 2024
1 parent 011ed09 commit 05aa342
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
25 changes: 0 additions & 25 deletions packages/plugin-svgr/modern.config.ts

This file was deleted.

11 changes: 5 additions & 6 deletions packages/plugin-svgr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
"type": "module",
"exports": {
".": {
"types": "./dist-types/index.d.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"types": "./dist-types/index.d.ts",
"types": "./dist/index.d.ts",
"files": [
"dist",
"compiled",
"dist-types"
"compiled"
],
"scripts": {
"build": "modern build",
"dev": "modern build --watch",
"build": "rslib build",
"dev": "rslib build --watch",
"prebundle": "prebundle"
},
"dependencies": {
Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-svgr/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { dualPackage } from '@rsbuild/config/rslib.config.ts';
import { defineConfig } from '@rslib/core';

export default defineConfig({
...dualPackage,
lib: [
...dualPackage.lib,
{
syntax: 'es2021',
format: 'cjs',
source: {
entry: {
loader: './src/loader.ts',
},
},
},
],
});
6 changes: 3 additions & 3 deletions packages/plugin-svgr/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { normalize } from 'node:path';
import { callbackify } from 'node:util';
import type { Rspack } from '@rsbuild/core';
import { type Config, type State, transform } from '@svgr/core';
import { type Config, type Plugin, type State, transform } from '@svgr/core';
import jsx from '@svgr/plugin-jsx';
import svgo from '@svgr/plugin-svgo';

Expand All @@ -34,11 +34,11 @@ function svgrLoader(
return exportMatches ? `export default ${exportMatches[1]}` : null;
})();

const state = {
const state: Partial<State> = {
caller: {
name: '@rsbuild/plugin-svgr',
previousExport,
defaultPlugins: [svgo, jsx],
defaultPlugins: [svgo, jsx] as unknown as Plugin[],
},
filePath: normalize(this.resourcePath),
};
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-svgr/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@rsbuild/config/tsconfig",
"extends": "@rsbuild/config/tsconfig-node16",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./",
Expand Down

0 comments on commit 05aa342

Please sign in to comment.