[unocss] exclude option is deprecated, use content.pipeline.exclude instead.

文章讲述了在使用@unocss/vite时,如何将旧版的exclude选项更新为content.pipeline.exclude以解决pnpmdev开发时的警告。作者提供了迁移配置的示例,以帮助读者避免此问题。

依赖

 "@unocss/vite": "^0.55.3",
 "unocss": "^0.55.2",

当我运行 pnpm dev 的时候给我报了这个 warn
[unocss] exclude option is deprecated, use content.pipeline.exclude instead.

解决

找到 unocss.config.ts 是因为这个配置导致的,之前我是这样的,如下:

import { defineConfig } from "@unocss/vite";

export default defineConfig({
  exclude: ["node_modules", "dist", ".git", ".husky", ".vscode", "public", "build", "mock", "./stats.html"]
});

修改之后:

import { defineConfig } from "@unocss/vite";

export default defineConfig({
  content: {
    pipeline: {
      exclude: ["node_modules", "dist", ".git", ".husky", ".vscode", "public", "build", "mock", "./stats.html"]
    }
  }
});

再次运行就不会出现了,希望能够帮到你解决问题~

Started by user administrator Obtained uat_tc/frontend/Jenkinsfile from git http://47.100.45.4:8060/pipeline/dbm-ci.git [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in /var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout The recommended git tool is: NONE using credential dbm-deploy > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url http://47.100.45.4:8060/pipeline/dbm-ci.git # timeout=10 Fetching upstream changes from http://47.100.45.4:8060/pipeline/dbm-ci.git > git --version # timeout=10 > git --version # 'git version 2.39.5' using GIT_ASKPASS to set credentials > git fetch --tags --force --progress -- http://47.100.45.4:8060/pipeline/dbm-ci.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 Checking out Revision 39c6e6fb53f67b249d725128e27fe95d10d8c634 (refs/remotes/origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f 39c6e6fb53f67b249d725128e27fe95d10d8c634 # timeout=10 Commit message: "前端部署脚本修改" > git rev-list --no-walk 39c6e6fb53f67b249d725128e27fe95d10d8c634 # timeout=10 [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Tool Install) [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Checkout) [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] withEnv [Pipeline] { [Pipeline] git The recommended git tool is: NONE using credential dbm-deploy > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url http://47.100.45.4:8060/ifourthwall-frontend/dbm-provider-miniapp-ext.git # timeout=10 Fetching upstream changes from http://47.100.45.4:8060/ifourthwall-frontend/dbm-provider-miniapp-ext.git > git --version # timeout=10 > git --version # 'git version 2.39.5' using GIT_ASKPASS to set credentials > git fetch --tags --force --progress -- http://47.100.45.4:8060/ifourthwall-frontend/dbm-provider-miniapp-ext.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/uat^{commit} # timeout=10 Checking out Revision d96cc2d276749987f956838156865e2c99d68c70 (refs/remotes/origin/uat) > git config core.sparsecheckout # timeout=10 > git checkout -f d96cc2d276749987f956838156865e2c99d68c70 # timeout=10 > git branch -a -v --no-abbrev # timeout=10 > git checkout -b uat d96cc2d276749987f956838156865e2c99d68c70 # timeout=10 Commit message: "合并分支 'test' 到 'uat'" First time build. Skipping changelog. [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Build) [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] withEnv [Pipeline] { [Pipeline] script [Pipeline] { [Pipeline] sh + rm -rf node_modules + node -v v18.20.3 + git remote set-url origin https://github.com/evrone/postcss-px-to-viewport.git + npm install --registry=https://registry.npmmirror.com npm warn deprecated yaeti@0.0.6: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. added 346 packages in 2s 77 packages are looking for funding run `npm fund` for details + npm run build:uat > cssccrane@0.0.0 build:uat > vite build --mode uat postcss-px-to-viewport: postcss.plugin was deprecated. Migration guide: https://evilmartians.com/chronicles/postcss-8-plugin-migration vite v5.4.20 building for uat... transforming... DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0. More info and automated migrator: https://sass-lang.com/d/import ╷ 1 │ @use "@/assets/css/constant.scss" as *;@import "./base.scss"; │ ^^^^^^^^^^^^^ ╵ src/assets/css/index.scss 1:48 root stylesheet DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0. More info and automated migrator: https://sass-lang.com/d/import ╷ 2 │ @import "./constant.scss"; │ ^^^^^^^^^^^^^^^^^ ╵ src/assets/css/index.scss 2:9 root stylesheet DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api ✓ 430 modules transformed. Generated an empty chunk: "@antfu". Generated an empty chunk: "vue". Generated an empty chunk: "vue-demi". x Build failed in 1.87s error during build: [vite:esbuild-transpile] Transform failed with 2 errors: assets/vant-!~{00b}~.js:2878:6: ERROR: The symbol "bem" has already been declared assets/vant-!~{00b}~.js:5104:6: ERROR: The symbol "bem" has already been declared  The symbol "bem" has already been declared 2876| const Tabs = withInstall(stdin_default$f); 2877| 2878| const [name$c, bem] = createNamespace("picker-group"); | ^ 2879| const PICKER_GROUP_KEY = Symbol(name$c); 2880| extend({ The symbol "bem" has already been declared 5102| const Notify = withInstall(stdin_default$2); 5103| 5104| const [name$1, bem, t] = createNamespace("search"); | ^ 5105| const searchProps = extend({}, fieldSharedProps, { 5106| label: String,  at failureErrorWithLog (/var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/node_modules/esbuild/lib/main.js:1472:15) at /var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/node_modules/esbuild/lib/main.js:755:50 at responseCallbacks.<computed> (/var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/node_modules/esbuild/lib/main.js:622:9) at handleIncomingPacket (/var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/node_modules/esbuild/lib/main.js:677:12) at Socket.readFromStdout (/var/jenkins_home/workspace/prd-frontend-dbm-provider-miniapp-ext/node_modules/esbuild/lib/main.js:600:7) at Socket.emit (node:events:517:28) at addChunk (node:internal/streams/readable:368:12) at readableAddChunk (node:internal/streams/readable:341:9) at Readable.push (node:internal/streams/readable:278:10) at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Deploy) Stage "Deploy" skipped due to earlier failure(s) [Pipeline] getContext [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE
最新发布
09-13
这是一个 Django REST Framework(DRF)中常见的错误: --- ## ❓错误信息: ``` Cannot set both 'fields' and 'exclude' options on serializer DrivingTestCaseSerializer. ``` --- ## ✅ 错误原因: 在 DRF 中,序列化器的 `Meta` 类中**不能同时设置 `fields` 和 `exclude`** 两个选项。它们是互斥的。 ```python class MySerializer(serializers.ModelSerializer): class Meta: model = MyModel fields = ['field1', 'field2'] exclude = ['field3'] # ❌ 这会导致冲突 ``` --- ## ✅ 解决方案 你只能选择以下一种方式: ### ✅ 方法一:使用 `fields`(显式包含字段) 只列出你需要的字段: ```python class DrivingTestCaseSerializer(BaseTestCaseSerializer): class Meta(BaseTestCaseSerializer.Meta): model = DrivingTestCase fields = ['associated_system_requirement_id', 'new_case_id', 'test_case_id', 'casetype'] ``` ### ✅ 方法二:使用 `exclude`(显式排除字段) 只列出你不需要的字段: ```python class DrivingTestCaseSerializer(BaseTestCaseSerializer): class Meta(BaseTestCaseSerializer.Meta): model = DrivingTestCase exclude = ['automation_case_id'] # 只排除这个字段 ``` --- ## ✅ 如果你继承了父类的 `Meta`,如何避免冲突? 如果你的 `BaseTestCaseSerializer` 中已经定义了 `fields` 或 `exclude`,那么子类应避免重复定义。 ### ✅ 推荐做法:父类不定义 `fields` 或 `exclude`,子类单独定义 ```python class BaseTestCaseSerializer(serializers.ModelSerializer): class Meta: model = BaseTestCase # 不设置 fields 或 exclude,让子类决定 ``` 然后子类根据需要选择 `fields` 或 `exclude`: ```python class DrivingTestCaseSerializer(BaseTestCaseSerializer): class Meta(BaseTestCaseSerializer.Meta): model = DrivingTestCase exclude = ['automation_case_id'] ``` 或者: ```python class DrivingTestCaseSerializer(BaseTestCaseSerializer): class Meta(BaseTestCaseSerializer.Meta): model = DrivingTestCase fields = ['associated_system_requirement_id', 'new_case_id', 'test_case_id', 'casetype'] ``` --- ## ✅ 高级用法:动态控制字段(推荐) 如果你希望更灵活地控制字段(比如根据请求动态决定),可以重写 `get_fields()` 方法: ```python class DrivingTestCaseSerializer(BaseTestCaseSerializer): def get_fields(self): fields = super().get_fields() # 动态移除 automation_case_id 字段 fields.pop('automation_case_id', None) return fields class Meta(BaseTestCaseSerializer.Meta): model = DrivingTestCase ``` --- ## ✅ 总结对比 | 方法 | 是否允许 | 说明 | |------|----------|------| | 同时设置 `fields` 和 `exclude` | ❌ 报错 | | 使用 `fields` | ✅ 推荐 | | 使用 `exclude` | ✅ 推荐 | | 使用 `get_fields()` 动态控制 | ✅ 推荐,最灵活 | | 父类定义 `fields` 或 `exclude`,子类再定义 | ⚠️ 容易冲突,需谨慎 | --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值