如何设置与业力和巴贝尔的汇总?

时间:2017-04-20 17:08:58

标签: karma-runner babel rollupjs

我尝试用业力和巴贝尔设置汇总进行测试。

我面临两个问题。

首先,它导致关于Uncaught TypeError的错误default

Uncaught TypeError: Cannot use 'in' operator to search for 'default' in undefined

其次,它没有找到外部依赖。

Treating 'chai' as external dependency

我的设置有什么问题?

rollup conf

import babel from "rollup-plugin-babel";
import babelrc from "babelrc-rollup";
import istanbul from "rollup-plugin-istanbul";
import nodeResolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
// import uglify from 'rollup-plugin-uglify'

let pkg = require('./package.json');
let external = Object.keys(pkg.dependencies);

export default {
    entry: 'src/index.js',
    plugins: [
        babel(babelrc()),
        istanbul({
            exclude: ['test/**/*', 'node_modules/**/*']
        }),
        globals(),
        builtins(),
        nodeResolve({
            module: true,
            jsnext: true,
            main: true,
            browser: true,
            extensions: ['.js']
        }),
        commonjs({
            include: 'node_modules/**'
        }),
        //uglify(),
    ],
    external: external,
    targets: [
        {
            dest: pkg.main,
            format: 'umd',
            moduleName: 'sketchbook',
            sourceMap: true
        },
        {
            dest: pkg.module,
            format: 'es',
            sourceMap: true
        }
    ]
};

karma conf

module.exports = function (config) {
    config.set({
        files: [
            // Watch src files for changes but
            // don't load them into the browser.
            {pattern: 'src/**/*.js', included: false},
            'test/**/*.spec.js',
        ],

        browsers: ['Chrome'],

        preprocessors: {
            'src/**/*.js': ['rollup'],
            'test/**/*.spec.js': ['rollup'],
        },

        rollupPreprocessor: {
            plugins: [
                require('rollup-plugin-buble')(),
            ],
            format: 'umd', // Helps prevent naming collisions.
            moduleName: 'sketchbook', // Required for 'iife' format.
            sourceMap: 'inline', // Sensible for testing.
        },

        customPreprocessors: {
            // Clones the base preprocessor, but overwrites
            // its options with those defined below.
            rollupBabel: {
                base: 'rollup',
                options: {
                    // In this case, to use
                    // a different transpiler:
                    plugins: [
                        require('rollup-plugin-babel')(),
                    ],
                }
            }
        }


        // frameworks: ['mocha'],
        // client: {
        //  mocha: {
        //      opts: 'test/mocha.opts'
        //
        //      // // change Karma's debug.html to the mocha web reporter
        //      // reporter: 'html',
        //      //
        //      // // require specific files after Mocha is initialized
        //      // require: [require.resolve('bdd-lazy-var/bdd_lazy_var_global')],
        //      //
        //      // // custom ui, defined in required file above
        //      // ui: 'bdd-lazy-var/global',
        //  }
        // }
    });
};

source

0 个答案:

没有答案