开玩笑不会转换node_module依赖项

时间:2020-11-05 20:58:04

标签: javascript jestjs babeljs rollup

我们的代码引用@myScope/vue-notify库,该库在汇总配置中设置为外部/全局库。该代码是ES6模块,需要转译才能使jest能够使用它,但是默认情况下,Jest不会转译node_modules文件夹。我曾尝试向transformIgnorePatterns添加否定的前瞻性,但是无论我尝试使用哪种组合,我都会不断收到此错误:

Error

我的Jest转换设置如下:

transform: {
    '.+\\.(css|css!|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
        'jest-transform-stub',
    '^.+\\.(js|jsx)?$': 'babel-jest',
},

transformIgnorePatterns: [
    '/node_modules/(?!@myScope/vue-notify)',
    '/dist/',
    '/docs/',
],

我的rollup.config.js如下:

import packageJson from './package.json';
import json from '@rollup/plugin-json';
import babel from '@rollup/plugin-babel';
import { addMinExtension } from './utils/utils';
import { terser } from 'rollup-plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

const globals = {
    DevExpress: 'DevExpress',
    jquery: '$',
    '@myScope/vue-notify': 'vueNotify',
    'file-saver': 'saveAs',
    exceljs: 'ExcelJS',
};
const externals = ['jquery', '@myScope/vue-notify', 'file-saver', 'exceljs'];

export default [
    {
        // Dev UMD Config:
        input: packageJson.input,
        output: [
            {
                name: packageJson.moduleName,
                file: packageJson.browser,
                format: 'umd',
                globals: globals,
            },
        ],
        external: externals,
        plugins: [
            nodeResolve(),
            commonjs({
                include: 'node_modules/**',
            }),
            json(),
            babel({ babelHelpers: 'runtime' }),
        ],
    },
    {
        // Dev Module Config:
        input: packageJson.input,
        output: [
            {
                file: packageJson.module,
                format: 'es',
            },
        ],
        external: externals,
        plugins: [
            nodeResolve(),
            commonjs({
                include: 'node_modules/**',
            }),
            json(),
        ],
    },
    {
        // Prod UMD Config:
        input: packageJson.input,
        output: [
            {
                name: packageJson.moduleName,
                file: addMinExtension(packageJson.browser),
                format: 'umd',
                sourcemap: true,
                globals: globals,
            },
        ],
        external: externals,
        plugins: [
            nodeResolve(),
            commonjs({
                include: 'node_modules/**',
            }),
            json(),
            babel({ babelHelpers: 'runtime' }),
            terser(),
        ],
    },
    {
        // Prod Module Config:
        input: packageJson.input,
        output: [
            {
                file: addMinExtension(packageJson.module),
                format: 'es',
            },
        ],
        external: externals,
        plugins: [
            nodeResolve(),
            commonjs({
                include: 'node_modules/**',
            }),
            json(),
            terser(),
        ],
    },
];

任何帮助使该工作正常进行的人都将得到帮助!

0 个答案:

没有答案