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;
}
相关推荐
黑臂麒麟13 小时前
Electron&OpenHarmony 跨平台实战开发(一):electron-vite 与 Vue3 架构搭建指南
前端·javascript·electron·openharmony
少寒14 小时前
深入理解JavaScript Promise:异步编程的基石
前端·javascript
tecwlcvi32314 小时前
安卓版谷歌地图,Google地图高清版,谷歌地球,谷歌翻译,谷歌(Chrome)浏览器,手机版Edge,浏览器等安卓版浏览器下载
前端·chrome·edge
czlczl2002092514 小时前
SpringBoot中web请求路径匹配的两种风格
java·前端·spring boot
2022.11.7始学前端14 小时前
n8n第四节 表单触发器:让问卷提交自动触发企微消息推送
java·前端·数据库·n8n
m0_7400437314 小时前
Axios 请求示例 res.data.data
前端·javascript·vue.js
程序员小寒14 小时前
超详细的 EventLoop 解读及模拟实现
前端·javascript
冴羽14 小时前
太好看了!3 个动漫变真人 Nano Banana Pro 提示词
前端·人工智能·aigc
zReadonly14 小时前
关于vxeTable转换树状表格以及问题思考
前端
锈儿海老师14 小时前
深入探究 React 史上最大安全漏洞
前端·react.js·next.js