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;
}
相关推荐
岁月宁静1 小时前
深度定制:在 Vue 3.5 应用中集成流式 AI 写作助手的实践
前端·vue.js·人工智能
心易行者2 小时前
10天!前端用coze,后端用Trae IDE+Claude Code从0开始构建到平台上线
前端
saadiya~2 小时前
ECharts 实时数据平滑更新实践(含 WebSocket 模拟)
前端·javascript·echarts
fruge2 小时前
前端三驾马车(HTML/CSS/JS)核心概念深度解析
前端·css·html
百锦再2 小时前
Vue Scoped样式混淆问题详解与解决方案
java·前端·javascript·数据库·vue.js·学习·.net
烛阴2 小时前
Lua 模块的完整入门指南
前端·lua
浪里行舟3 小时前
国产OCR双雄对决?PaddleOCR-VL与DeepSeek-OCR全面解析
前端·后端
znhy@1234 小时前
CSS易忘属性
前端·css
瓜瓜怪兽亚4 小时前
前端基础知识---Ajax
前端·javascript·ajax
AI智能研究院4 小时前
(四)从零学 React Props:数据传递 + 实战案例 + 避坑指南
前端·javascript·react.js