alibaba / ice

🚀 ice.js: The Progressive App Framework Based On React(基于 React 的渐进式应用框架)
https://ice.work
MIT License
17.84k stars 2.09k forks source link

vite模式下配置postcssOptions 运行报错 #5359

Closed CL-nevins closed 2 years ago

CL-nevins commented 2 years ago

What is the current behavior? 发生了什么?

我想在ice vite模式里开启postcss nested,使用npm init ice <project-name>创建项目,模板选择为TypeScript + FuSion Design,安装完依赖后,我参照官方配置文档,尝试在build.json里,添加postcssOptions配置:

{
  "vite": true,
  "plugins": [
    [
      "build-plugin-moment-locales",
      {
        "locales": ["zh-cn"]
      }
    ],
    [
      "build-plugin-ignore-style",
      {
        "libraryName": "@alifd/next"
      }
    ]
  ],
+ "postcssOptions": {
+ "plugins": {
+      "postcss-preset-env": {
+        "browsers": ["last 2 versions"]
+    },
+    "postcss-import": false,
+    "postcss-short": { "prefix": "x" }
+  },
+  "syntax": "sugarss",
+   "parser": "sugarss",
+ "stringifier": "sugarss"
+ }
}

运行npm start后,提示:

ERR! CONFIG Failed to get config.
ERR! Cannot find module 'postcss-preset-env'

这是什么情况,postcss-preset-env不是内置了吗? 我将postcss-preset-env换成postcss-nested也是一样,提示未找到模块;

What is the expected behavior? 期望的结果是什么?

{
  "vite": true,
  "plugins": [
    [
      "build-plugin-moment-locales",
      {
        "locales": ["zh-cn"]
      }
    ],
    [
      "build-plugin-ignore-style",
      {
        "libraryName": "@alifd/next"
      }
    ]
  ],
+ "postcssOptions": {
+   "plugins": {
+    "postcss-nested": true
+  }
+ }
}

Any additional comments? 相关环境信息?

ClarkXia commented 2 years ago

vite 模式下默认没有内置任何 plugins,至于 postcss-preset-env require 不到是因为内置的 postcss 相关插件都已经经过预打包

CL-nevins commented 2 years ago

了解了,安装了postcss-nested后设置生效了,谢谢