鍍金池/ 問答/HTML/ vue-cli3.0創(chuàng)建的項目怎么配置postcss?

vue-cli3.0創(chuàng)建的項目怎么配置postcss?

問題描述

我使用vue-cli 3.0版,創(chuàng)建了一個hello-world項目:

vue create hello-world
// 之后選擇默認選項開始創(chuàng)建

我發(fā)現(xiàn)它使用:vue serve就開啟了服務(wù)

現(xiàn)在我想加入 postcss,發(fā)現(xiàn)它生成的 pkg.json 里面已經(jīng)寫了這樣的配置:

"postcss": {
  "plugins": {
    "autoprefixer": {}
  }
},

這不像我之前使用的 webpack 的配置方式。

請問現(xiàn)在我要加入postcss,需要怎樣來配置它呢?
是否還是需要像原來的 webpack 的配置方式?

相關(guān)代碼

// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)
這是創(chuàng)建好項目后的pkg.json內(nèi)容:

{
  "name": "hello-world",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "vue": "^2.5.16"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.0.0-rc.9",
    "@vue/cli-plugin-eslint": "^3.0.0-rc.9",
    "@vue/cli-service": "^3.0.0-rc.9",
    "vue-template-compiler": "^2.5.16"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

感謝!

回答
編輯回答
有點壞

@kybetter 請問是如何解決的? 遇到配置‘postcss-pxtorem’, 我寫在vue.config.js中 不生效,問題基本和題主一樣

css: {
    loaderOptions: {
        postcss: {
            'postcss-pxtorem': {
                 rootValue: 75
             },
            'postcss-theme-variables': {
                vars: {
                    white: '#000'
                },
                prefix: '$'
            }
        }
    }
}
2017年3月19日 01:50
編輯回答
不二心

已自行解決,關(guān)閉答案。

2017年12月16日 09:57