如何在 vite 构建中配置 jsc.parser.usingDecl?

问题描述 投票:0回答:1

我按照Vite插件Web扩展教程来构建跨浏览器扩展。

我正在使用

typescript
5.3.2
,我的代码使用
using
关键字 自动调用
dispose

当我尝试运行

vite build
时,我得到:

Using declaration is not enabled. Set jsc.parser.usingDecl to true (Note that you need plugins to import files that are not JavaScript)
file: C:/Users/xxxxx/source/repos/.../types.ts:73:14
71:
72:         //NOTE: learn more about 'using' keyword: https://www.typescriptlang.org/docs/handbook/release-notes/typescri...
73:         using awaiter = new RequestMonitor();

这是我的

vite.config.ts

import { defineConfig } from "vite";
import webExtension, { readJsonFile } from "vite-plugin-web-extension";

const target = process.env.TARGET || "chrome";

function generateManifest() {
  const manifest = readJsonFile(`src/manifest.${target}.json`);
  const pkg = readJsonFile("package.json");
  return {
    name: `${pkg.name} (${target})`,
    description: `${pkg.description} for ${target}`,
    version: pkg.version,
    ...manifest,
  };
}

export default defineConfig({
  define:{
    __BROWSER__: JSON.stringify(target)
  },
  publicDir: "assets",
  build: {
    outDir: "build"
  },
  plugins: [
    webExtension({
      manifest: generateManifest,
      watchFilePaths: ["package.json", "manifest.json"],
      browser: target,
    }),
  ],
});

如何将

jsc.parser.usingDecl
设置为 true

typescript google-chrome-extension vite browser-extension
1个回答
0
投票

我来到这里尝试在测试中使用

using
关键字运行 vitest 这是我解决问题的方法:

  1. 更新您的汇总,使其 >= 4.14 (
    npm update rollup
    )
  2. 将此添加到您的
    vitest.config.ts
import {defineConfig} from 'vitest/config';

export default defineConfig({
  // ...
  esbuild: {
    target: 'ES2022',
  },
});
© www.soinside.com 2019 - 2024. All rights reserved.