问题描述
在使用 father 打包库的时候,想移除代码中的导入css语句:
import './index.less'
解决方法
father 本身使用 babel 来进行打包的,想实现这种功能需要配置babel 的打包插件,目前可以实现需求的是babel-plugin-transform-remove-imports
这个包,地址如下:
www.npmjs.com/package/bab…
使用方法如下, 修改 fatherrc.ts 配置文件:
# fatherrc.ts
import { defineConfig } from 'father';
export default defineConfig({
extraBabelPlugins: [
[
'./node_modules/babel-plugin-transform-remove-imports',
{
// 匹配的非js文件类型
test: '\.(less)$',
},
],
],
});