Jinjiang/px2rem-loader

使用vue-cli3.0.0脚手架创建的项目,添加px2rem-loader运行报错

Closed this issue · 1 comments

添加方法:
按照官方文档https://cli.vuejs.org/guide/webpack.html#simple-configuration
在项目根目录添加vue.config.js并配置:

module.exports = {
  ...
  chainWebpack: config => {
    function generateLoaders (loader) {
      config.module
        .rule(loader)
        .oneOf('vue')
        .use('px2rem-loader')
        .loader('px2rem-loader')
        .options({ remUnit: 75, remPrecision: 8 })
        .end()
      config.module
        .rule(loader)
        .oneOf('normal')
        .use('px2rem-loader')
        .loader('px2rem-loader')
        .options({ remUnit: 75, remPrecision: 8 })
        .end()
    }
    generateLoaders('css')
    generateLoaders('less')
  },
  ...
}

在vue文件写less时编译会报错,而通过<style src="./App.less"></style>的引用可以正常通过

报错信息:

yarn run v1.3.2
$ vue-cli-service serve
 INFO  Starting development server...
 94% after seal

 ERROR  Failed to compile with 1 errors                                                                                                                       12:11:50

 error  in ./src/modules/static_index/App.vue?vue&type=style&index=0&lang=less

Module build failed (from ./node_modules/px2rem-loader/index.js):
Error: undefined:85:3: missing '}'
    at error (/Users/smk17/VsCode/ydy-index/node_modules/css/lib/parse/index.js:62:15)
    at declarations (/Users/smk17/VsCode/ydy-index/node_modules/css/lib/parse/index.js:260:26)
    at rule (/Users/smk17/VsCode/ydy-index/node_modules/css/lib/parse/index.js:561:21)
    at rules (/Users/smk17/VsCode/ydy-index/node_modules/css/lib/parse/index.js:118:70)
    at stylesheet (/Users/smk17/VsCode/ydy-index/node_modules/css/lib/parse/index.js:81:21)
    at Object.module.exports [as parse] (/Users/smk17/VsCode/ydy-index/node_modules/css/lib/parse/index.js:565:20)
    at Px2rem.generateRem (/Users/smk17/VsCode/ydy-index/node_modules/px2rem/lib/px2rem.js:70:20)
    at Object.module.exports (/Users/smk17/VsCode/ydy-index/node_modules/px2rem-loader/lib/px2rem-loader.js:7:20)

 @ ./node_modules/vue-style-loader??ref--10-oneOf-1-0!./node_modules/css-loader??ref--10-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/lib??ref--10-oneOf-1-2!./node_modules/less-loader/dist/cjs.js??ref--10-oneOf-1-3!./node_modules/px2rem-loader??ref--10-oneOf-1-4!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/modules/static_index/App.vue?vue&type=style&index=0&lang=less 4:14-515 14:3-18:5 14:515-18:4 15:22-523
 @ ./src/modules/static_index/App.vue?vue&type=style&index=0&lang=less
 @ ./src/modules/static_index/App.vue
 @ ./src/modules/static_index/main.js
 @ multi (webpack)-dev-server/client?http://192.168.0.128:8081/sockjs-node (webpack)/hot/dev-server.js ./src/modules/static_index/main.js

为什么关闭了,连个说明都没有