This time I will bring you a detailed explanation of the automatic construction of rem on the mobile terminal of webpack. What are the precautions for automatic construction of rem on the mobile terminal of webpack? The following is a practical case, let's take a look.
1 Following the old video tutorial, I found that the various plug-in versions of node npm webpack px2rem are different and useless at all 2. The tutorials on the Internet were lacking and incomplete. It took me a long time to figure it out. I thought about manually setting the cssrem of vscode, but I was still not convinced. I pieced it together and finally figured it out. The following method is provided, I hope it will be helpful for everyone to automatically build rem for mobile terminals 1 I won’t go into detail about installing vue-cli, everyone should know it 2 Install and configure px2rem-loader (postcss is not used here. After trying many problems, I decided to use this) The first step: npm install px2rem-loader Part 2: Addmodule.exports={ module: { rules: [ { test: /\.(css|less|scss)(\?.*)?$/, loader: 'style-loader!css-loader!sass-loader!less-loader!postcss-loader' } ] } }
plugins: [ new webpack.LoaderOptionsPlugin({ // webpack 2.0之后, 此配置不能直接写在自定义配置项中, 必须写在此处 vue: { postcss: [require('postcss-px2rem')({ remUnit: 40, propWhiteList: [] })] } } ]
const cssLoader = { loader: 'css-loader?importLoaders=1', options: { minimize: process.env.NODE_ENV === 'production', sourceMap: options.sourceMap } }
font-size:40px
Output font-size:1rem (under iphone) 3 We all know that the pixel ratio of devices is different, so we use hotcss to adjust the pixel ratio of the device. Link I put it in src/assets/js/, you can follow your habits To introduce a method, you can define any name yourself. Here I changed hotcss.js toviewport.js
module.exports = { entry: { app: './src/main.js', rem: './src/assets/js/viewport.js' } }
How to use PHP’s iterator interface Iterator
php to decompress the contents of the zip package to the specified directory Detailed explanation of steps
The above is the detailed content of Detailed explanation of webpack's mobile terminal automated construction rem method. For more information, please follow other related articles on the PHP Chinese website!