postcss-preset-env选项importFrom不生效问题

215 阅读1分钟

postcss 插件 postcss-preset-env importFrom 选项不生效

postcss-preset-env 的importFrom已经被移除,现在需要使用使用插件postcss-global-data

安装 postcss-global-data

npm i -D @csstools/postcss-global-data

使用 postcss-global-data

const postcssGlobalData = require('@csstools/postcss-global-data');
const postcssPresetEnv = require('postcss-preset-env')
const path from "node:path"
//vite.config.js 
export default defineConfig({
    ...
    css:{
        postcss:{
            plugins:[
                postcssGlobalData({
                    files:[
                        path.resolve(process.cwd(),"引入文件路径")
                    ]
                }),
                postcssPresetEnv()
            ]
        }
    }
})

//postcss.config.js
export default {
    plugins:[
        postcssGlobalData({
            files:[
                path.resolve(process.cwd(),"引入文件路径")
            ]
        }),
        postcssPresetEnv()
    ]
}