2

我有一个 karma conf,我尝试使用 babel/browserify 进行工作。它看起来像这样:

module.exports = function(config) {
config.set({
    browsers: ['Chrome'],
    frameworks: ['jasmine'],
    plugins: [
        'karma-jasmine',
        'karma-chrome-launcher',
        'karma-babel-preprocessor',
        'karma-browserify'
    ],
    preprocessors: {
        '../src/**/*.js': ['babel', 'browserify'],
        'unit/*.spec.js': ['babel', 'browserify']
    },
    files: [
        '../src/**/*.js',
        'unit/*.spec.js'
    ],
    babelPreprocessor: {
        options: {
            presets: ['es2015'],
            sourceMap: 'inline'
        },
        filename: function (file) {
            return file.originalPath.replace(/\.js$/, '.es5.js');
        },
        sourceFileName: function (file) {
            return file.originalPath;
        }
    }
});

};

每次我通过 gulp babel 预处理器运行此配置时,都会返回以下错误:错误 [preprocessor.babel]: Cannot read property 'bundleFile' of undefined

4

2 回答 2

6

尝试将 'browserify' 添加到 'frameworks',如下所示: frameworks: ['browserify', 'jasmine']

我有同样的错误,通过这样做修复。这是我的工作业力配置

module.exports = function (config) {
    config.set({
        browsers: ['Chrome'],
        singleRun: true,
        frameworks: ['browserify', 'mocha'],
        reporters: ['dots'],
        files: ['./*test.js'],
        preprocessors: {
            '*.js': ['browserify']
        },
        logLevel: 'LOG_DEBUG',
        browserify: {
            debug: true,
            transform: [ ['babelify', {presets: ['es2015', "react"]} ] ]
        }
    });
};
于 2016-08-02T13:42:50.280 回答
0

固定配置文件:

module.exports = function(config) { config.set({ browsers: ['Chrome'], frameworks: ['jasmine', 'browserify'], plugins: [ 'karma-jasmine', 'karma-chrome-launcher', 'karma-babel-preprocessor', 'karma-browserify' ], preprocessors: { '../src/js/app.js': ['browserify'], '../src/js/login/login-ctrl.js': ['browserify'], './unit/*.spec.js': ['browserify'] }, files: [ '../../node_modules/angular/angular.js', '../../node_modules/angular-mocks/angular-mocks.js', '../src/js/app.js', '../dist/js/partials/templates-all.js', '../src/js/login/login-ctrl.js', 'unit/*.spec.js' ], browserify: { debug: true, transform: [ ['babelify'] ] }, singleRun: false, reporters: ['progress'], colors: true }); };

于 2016-09-22T11:54:18.193 回答