rsbuild-插件

实现一个 rsbuild的插件

当前版本rsbuild版本

json 复制代码
{
  "devDependencies": {
    "@rsbuild/core": "^1.3.1",
    "@rsbuild/plugin-vue": "^1.0.7"
  }
}

实现plugins

js 复制代码
// rsbuild.config.mjs

import { defineConfig } from '@rsbuild/core';
import { stylelintPlugin } from './plugins/stylelintPlugin';

export default defineConfig({
  plugins: [
    pluginVue(),
    stylelintPlugin({
      files: ['**/*.css', '**/*.scss'],
      exclude: /node_modules/,
      fix: true
    })
  ]
});
js 复制代码
// plugins/stylelintPlugin.js

export const stylelintPlugin = (options = {}) => ({
  name: 'stylelint-plugin',
  setup(api) {
    api.onBeforeStartDevServer(async () => {
      const { default: stylelint } = await import('stylelint');

      const result = await stylelint.lint({
        files: options.files || 'src/**/*.{css,scss,less}',
        fix: options.fix || false,
        formatter: 'string'
      });

      if (result.results.length > 0) {
        console.error(result.report);
      }
    });
  }
});

实现一个loader

js 复制代码
// rsbuild.config.mjs

import { defineConfig } from '@rsbuild/core';
import { pluginVue } from '@rsbuild/plugin-vue';
import path from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default defineConfig({
  plugins: [
    pluginVue(),
  ],
  tools: {
    rspack: (config) => {
      config.module.rules.push({
        test: /\.(js|vue)$/,
        exclude: /node_modules/,
        enforce: 'pre',
        use: [path.resolve(__dirname, 'custom-loader.js')]
      });
      return config;
    }
  }
});

同webpack-loader

js 复制代码
// custom-loader.js

export default function (source) {
  return source;
}
相关推荐
mCell5 小时前
【短文】不是最强,是最适合
前端·aigc·deepseek
余瑜鱼鱼鱼6 小时前
HTML常用标签总结
前端·html
Jave21086 小时前
Vue 中 mixins 混合开发的主要使用场景有哪些?
前端·vue.js
徐同保6 小时前
openclaw安装
前端
JEECG低代码平台6 小时前
JeecgBoot低代码平台 Ant Design Vue 4.x 升级避坑指南
前端·vue.js·低代码
yashuk6 小时前
Go-Gin Web 框架完整教程
前端·golang·gin
唐叔在学习7 小时前
e.preventDefault()到底怎么用?
前端·javascript
北寻北爱7 小时前
面试题-vue篇
前端·vue.js
XPoet7 小时前
AI 编程工程化:Skill——给你的 AI 员工装上技能包
前端·后端·ai编程
JEECG低代码平台7 小时前
JeecgBoot低代码平台 Qiankun 微前端集成指南:主应用配置全流程
前端·低代码