Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
webpack-ant-icon-loader
Advanced tools
用于解决 在引入ant-design
3.x
版本后(全量引入@ant-design/icons
图标文件),导致打包生成的主文件较大的问题。
npm
npm install webpack-ant-icon-loader --save-dev
yarn
yarn add webpack-ant-icon-loader --dev
webpack.config.js
module.exports = {
module:{
rules:[
{
loader:'webpack-ant-icon-loader',
enforce: 'pre',
include:[
require.resolve('@ant-design/icons/lib/dist')
]
}
]
}
}
.umirc.js
export default {
chainWebpack(config, { webpack }) {
// code split @ant-design/icons
config.module
.rule('@ant-design/icons')
.include.add(require.resolve('@ant-design/icons/lib/dist')).end()
.use('ant-icon')
.loader('webpack-ant-icon-loader');
},
}
react-app-rewired
config-overrides.js
const path = require('path');
module.exports = {
// The Webpack config to use when compiling your react app for development or production.
webpack: function (config, env) {
// ...add your webpack config
// add webpack-ant-icon-loader
config.module.rules.push({
loader: 'webpack-ant-icon-loader',
enforce: 'pre',
include: [
require.resolve('@ant-design/icons/lib/dist')
]
})
return config;
},
}
customize-cra
config-overrides.js
const path = require('path');
const { override } = require('customize-cra');
module.exports = override(
// add webpack-ant-icon-loader
(config) => {
config.module.rules.push({
loader: 'webpack-ant-icon-loader',
enforce: 'pre',
include: [
require.resolve('@ant-design/icons/lib/dist')
]
});
return config;
},
);
主要通过webpack
代码拆分(import
)来完成体积优化:
把@antd-design/icons/lib/dist
的图标文件拆成独立的chunk
,且异步加载后自动注册该图标文件图标。
由于ant design
内部组件使用了很多图标,所以不考虑按需加载图标的方案,仅仅是将图标文件拆分出来,减少主文件
的体积,(类似于加载独立的字体文件)。
通过webpack-ant-icon-loader
提供的runtime.js
来完成延迟加载图标的刷新。
由于使用了异步加载图标文件的原因,在首次进入页面后,会导致已渲染的图标组件但是还未注册的图标
会出现空白,解决这个问题,需要触发一次组件刷新, 所以通过runtime.js
在异步图标文件加载完成后,从最小层面(仅刷新已渲染但是未注册的的图标
)进行一次性组件刷新。刷新完毕后,runtime.js
将不再介入操作,一切回归原始流程。
ant design
推出了解决方案,仅需要从webpack.config.js
中移除当前loader
即可。基于 MIT License 开源,使用代码只需说明来源,或者引用 license.txt 即可。
FAQs
ant design icons code split loader
The npm package webpack-ant-icon-loader receives a total of 0 weekly downloads. As such, webpack-ant-icon-loader popularity was classified as not popular.
We found that webpack-ant-icon-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.