webpack 是如何打包的 实现一个支持全量加载/按需加载的组件库,目前内部并没有组件
npm i violetrosez-lib -S
该组件库可 整体加载,也支持 按需加载
import violetrosezLib from "violetrosez-lib";
import { comp1 } from "violetrosez-lib";
按需加载通过 babel-plugin-component
插件实现
npm i babel-plugin-component -D
npm install --save-dev babel-loader @babel/core
module.exports = {
...
module: {
rules: [
...
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
...
]
}
...
}
npm install @babel/preset-env --save-dev
{
"presets": ["@babel/preset-env"],
"plugins": [
[
"component",
{
"libraryName": "violeterosez-lib",
"style": false
}
]
]
}