小编Vyt*_*vys的帖子

如何在构建过程中排除 next.js 中的测试文件?

我正在创建 next.js 应用程序,并在页面目录中进行测试。为此,我已将配置添加到 next.config.js

const { i18n } = require('./next-i18next.config');

const nextConfig = {
    reactStrictMode: true,
    pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
    styledComponents: true,
    i18n,
};

module.exports = nextConfig;

Run Code Online (Sandbox Code Playgroud)

我的所有页面都有一个扩展名 page.tsx。例如 Home.page.tsx。我的测试文件命名如下:Home.spec.tsx。

问题是,我的测试文件仍然包含在构建中。我确实将它们排除在我的 tsconfig 文件中

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "esModuleInterop": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve",
        "incremental": true,
        "types": ["node", "jest", "@testing-library/jest-dom"]
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
    "exclude": ["node_modules", "**/*.spec.ts", "**/*.spec.tsx"] …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs webpack jestjs next.js

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

jestjs ×1

next.js ×1

reactjs ×1

typescript ×1

webpack ×1