You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Vue CLI 3(Beta 7)正确添加PostCSS支持?

Fixing PostCSS Support in Vue CLI 3 (Beta 7)

Hey there, I’ve run into similar quirks with early Vue CLI 3 betas—let’s get this sorted out for you! The error you’re seeing happens because Webpack doesn’t know how to handle .pcss files out of the box in this beta version, so we need to add the right loaders and configuration to make it work.

Here’s what you need to do step by step:

1. Install Required Dependencies

First, install the loaders and PostCSS plugins you’re using (including the postcss-smart-import you mentioned):

npm install postcss-loader css-loader postcss-smart-import autoprefixer --save-dev
# Or if you prefer Yarn:
yarn add postcss-loader css-loader postcss-smart-import autoprefixer -D

2. Add Webpack Rule for .pcss Files

Vue CLI 3 lets you customize Webpack config via a vue.config.js file (create this in your project root if it doesn’t exist). Add one of these configurations to teach Webpack how to process .pcss files:

module.exports = {
  chainWebpack: config => {
    // Create a rule specifically for .pcss files
    config.module
      .rule('pcss')
      .test(/\.pcss$/)
      // First use css-loader to resolve imports in the file
      .use('css-loader')
        .loader('css-loader')
        .end()
      // Then process the file with postcss-loader
      .use('postcss-loader')
        .loader('postcss-loader')
        .end()
  }
}

Option 2: Using configureWebpack (direct Webpack config)

module.exports = {
  configureWebpack: {
    module: {
      rules: [
        {
          test: /\.pcss$/,
          use: ['css-loader', 'postcss-loader']
        }
      ]
    }
  }
}

3. Complete Your postcssrc.js Config

Your current config looks truncated—make sure it’s fully set up with all the plugins you need:

module.exports = {
  plugins: {
    'postcss-smart-import': {}, // Handles smart import logic
    'autoprefixer': {} // Adds vendor prefixes to your CSS
    // Add other PostCSS plugins here if you need them (e.g., postcss-nested)
  }
}

4. Restart Your Dev Server

Stop your running npm run serve (or yarn serve) process and restart it—this ensures the new Webpack configuration is loaded properly.

After these steps, your import './index.pcss' should work without that "Module parse failed" error!

内容的提问来源于stack exchange,提问作者Nikos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:58:34