移动端css px自动转换成rem:
px2rem-loader:
{
loader: 'px2rem-loader',
options: {
remUnit: 75,
// 1个rem是多少px, 一般以750设计稿,
vw/10是75 remPrecision: 8
// rem计算保留8个小数点
} }
静态资源内联:
css内联:
方法一:借助style-loader:
{ loader: 'style-loader', options: { insert: 'top',
// 样式插入到<head>
injectType: 'singletonStyleTag',
// 将所有的style标签合并成一个 } } }
方法二:html-inline-css-webpack-plugin:
将<link rel="stylesheet" /> => <style>...<style/>
const HTMLInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default; ... plugins: [ new HTMLInlineCSSWebpackPlugin() ]
raw-loader: 只能安装0.5.1版本,否则会报错
html-webpack-plugin: html压缩的plugin.可以自动创建html模板组件,默认支持html、ejs, 其他模板引擎需要相关加载器。
<!DOCTYPE html> <html lang="en"> <head> ${ require('raw-loader!./meta.html') } <title>Document</title> <script>${ require('raw-loader!babel-loader!../node_modules/lib-flexible/flexible.js') }</script> </head> <body> <div id="root"></div> </body> </h