分类 web前端 下的文章



出错原因:做一个移动端的项目,安装了postcss-px2rem,同时安装了vant插件,在全局引入时,main.js导入vant样式文件报错以上错。

百度出错原因是因为postcss-px2rem

解决方案:卸载postcss-px2rem,下载postcss-pxtorem,postcss-pxtorem也是一款postcss插件,用于将css单位转化为rem,用于移动端适配,同时在postcss.config.js设置如下代码,没有这个文件可以自己创建该文件夹。amfe-flexible ,添加 根节点 font-size

npm install autoprefixer postcss-pxtorem amfe-flexible --save-dev

const autoprefixer = require('autoprefixer')
const px2rem = require('postcss-pxtorem')

module.exports = {
  plugins: [autoprefixer(), px2rem({ rootValue: 75, unitPrecision: 5, propList: ['*'] })]
}

main.js 增加

import 'amfe-flexible'

安装 uglifyjs-webpack-plugin

npm install uglifyjs-webpack-plugin --save-dev

vue.config.js

const UglifyJsPlugin = require('uglifyjs-webpack-plugin') //引入插件
configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    
    optimization: {
      minimizer: [
        new UglifyJsPlugin({
          uglifyOptions: {
            // 删除注释
            output: {
              comments: false
            },
            // 删除console debugger 删除警告
            compress: {
              drop_console: true, //console
              drop_debugger: false,
              pure_funcs: ['console.log'] //移除console
            }
          }
        })
      ]
    }
  },

nrm

nrm(npm registry manager )是npm的镜像源管理工具。

一、nrm操作

1、全局安装nrm

npm install nrm -g --save

2、nrm有自带默认配置,*为当前的配置

nrm ls

npm -------- https://registry.npmjs.org/

  yarn ------- https://registry.yarnpkg.com/

  cnpm ------- http://r.cnpmjs.org/

  nj --------- https://registry.nodejitsu.com/

  npmMirror -- https://skimdb.npmjs.com/registry/

3、切换当前源地址

nrm use taobao

4、删除源地址

nrm del taobao

3、添加源地址

nrm add https://.**/

4、测试时间

nrm test npm 

二、其他操作

1、直接安装cnpm 

npm install cnpm -g --registry=https://registry.npm.taobao.org

2、直接更改源地址

npm set registry https://registry.npm.taobao.org/

3、查看npm源地址

npm config list

4、删除源地址

npm config rm registry