1. 程式人生 > >vue配置px轉rem

vue配置px轉rem

1.下載lib-flexible

npm i lib-flexible --save

2.在index.html中

<html data-dpr = '1'> 在common.css中寫   html { font-size: 10vw; }

3.設定meta標籤

<meta name="viewport" content="width=device-width, initial-scale=1.0">

4.安裝px2rem-loader

npm install px2rem-loader

5.配置px2rem-loader

在build檔案中找到util.js,將px2rem-loader新增到cssLoaders中,如:

const cssLoader = {
loader: 'css-loader',
options: {
minimize: process.env.NODE_ENV === 'production',
sourceMap: options.sourceMap
}
}
const px2remLoader = {
loader: 'px2rem-loader',
options: {
remUnit: 75
}
}

 

同時,在generateLoaders方法中新增px2remLoader

function generateLoaders (loader, loaderOptions) {
const loaders = [cssLoader,px2remLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}

 

6.重啟,一切ok~

npm run dev