katoto-copy-skeleton-plugin clone ElemeFE 的版本,修改一下业务相关的东西
MIT License
对比情况看下下图:
骨架屏指的是当你打开一个 web 页面,在页面解析和数据加载之前,首先展示给用户大概的样式。
最终效果,"从9534行, 减到6987行"
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { SkeletonPlugin } = require("page-skeleton-webpack-plugin");
const path = require("path");
const webpackConfig = {
entry: "index.js",
output: {
path: __dirname + "/dist",
filename: "index.bundle.js"
},
plugin: [
new HtmlWebpackPlugin({
// Your HtmlWebpackPlugin config
}),
new SkeletonPlugin({
pathname: path.resolve(__dirname, `${customPath}`), // the path to store shell file
staticDir: path.resolve(__dirname, "./dist"), // the same as the `output.path`
routes: ["/", "/search"] // Which routes you want to generate skeleton screen
})
]
};
"scripts": {
"dev": "cross-env NODE_ENV=development node server.js",
"build": "rm -rf dist && cross-env NODE_ENV=production webpack --progress --hide-modules"
}
index.html
of html-webpack-pluginAdd comment <!-- shell -->
in the root element of you application.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="app">
<!-- shell -->
</div>
</body>
</html>
Default options
const pluginDefaultConfig = {
port: "8989",
text: {
color: "#EEEEEE"
},
image: {
shape: "rect", // `rect` | `circle`
color: "#EFEFEF",
shapeOpposite: []
},
button: {
color: "#EFEFEF",
excludes: []
},
svg: {
color: "#EFEFEF",
shape: "circle", // circle | rect
shapeOpposite: []
},
pseudo: {
color: "#EFEFEF", // or transparent
shape: "circle" // circle | rect
},
device: "iPhone 6 Plus",
debug: false,
minify: {
minifyCSS: { level: 2 },
removeComments: true,
removeAttributeQuotes: true,
removeEmptyAttributes: false
},
defer: 5000,
excludes: [],
remove: [],
hide: [],
grayBlock: [],
cookies: [],
cssUnit: "rem",
decimal: 4,
logLevel: "info",
quiet: false,
noInfo: false,
logTime: true
};