安装yarn add babel-plugin-import
实现按需加载组件代码和样式的babel插件
下载babel-plugin-import插件,然后在webpack.config.dev.js中的plugins添加配置
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
'babel-preset-react-app/webpack-overrides'
),
plugins: [
[
require.resolve('babel-plugin-named-asset-import'),
{
loaderMap: {
svg: {
ReactComponent: '@svgr/webpack?-prettier,-svgo![path]',
},
},
},
],
['import',{libraryName:'antd',style:true}],
],
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
// Don't waste time on Gzipping the cache
cacheCompression: false,
},
},
重启项目后报错:
打开项目package.json发现less版本是^3.0.4
目前来看,解决方案:将less版本降到3.0以下 比如安装 2.7.3版本。
两种方式:
1.yarn add less@^2.7.3
2.打开项目的package.json 找到dependencies下面的less 将其版本改为 "2.7.3" 然后 yarn install
作者:a伊雪
来源:CSDN
原文:https://blog.csdn.net/u010565037/article/details/86154544
版权声明:本文为博主原创文章,转载请附上博文链接!