Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma doesn't execute Babel within Webpack3 module.exports as a function configuration #297

Closed
nitinsurana opened this issue Jan 24, 2018 · 2 comments

Comments

@nitinsurana
Copy link

nitinsurana commented Jan 24, 2018

Webpack version:
3.8.1

Webpack Karma version:
2.0.5

Karma version:
1.7.1

Please tell us about your environment:
Windows 10

Browser: [Phantom XX | Chrome XX | Firefox XX | IE XX | Safari XX | Other XX]
Chrome + Firefox + IE

Current behavior:
Arrow functions are not transpiled.

Expected/desired behavior:
Arrow functions should be transpiled using the babel-loader configuration in webpack.config.js

  • What is the expected behavior?
    Arrow functions do not transpile and hence, IE 11 breaks.

webpack.config.js

const path = require('path')
const buildCore = true

module.exports =
    // function (env) {
    // const buildCore = env && env.core || false
    // console.log("Building core : ", buildCore)
    // return
    {
        context: path.resolve('src'),
        entry: {
            app: buildCore ? './nn-core-main' : './nn-standard-main'
        },
        output: {
            path: path.resolve('dist'),
            filename: buildCore ? 'nn-core.js' : 'nn-standard.js',
            publicPath: '/dist/'
        },
        module: {
            loaders: [
                {
                    loader: "babel-loader",
                    include: [
                        path.resolve(__dirname, "src"),
                    ],
                    exclude: [
                        path.resolve(__dirname, "node_modules"),
                    ],
                    query: {
                        presets: ['es2015']
                    },
                    test: /\.jsx?$/
                },
            ]
        }
    }
// }

Above works like a charm with both webpack and karma start --auto-watch commands. But if the commented lines are uncommented accordingly, then the transpiling fails, resulting in error in IE11.

karma.conf.js

var webpackConfig = require('./webpack.config');
webpackConfig.entry = function(){return {}};

module.exports = function (config) {
    config.set({
        browsers: ['IE_no_addons', 'Chrome', 'Firefox'],
        customLaunchers: {
            IE_no_addons: {
                base: 'IE',
                flags: ['-extoff']
            }
        },
        files: [
            'src/util/zet.js',
            'src/util/zet.test.js',
            'src/util/serialization.js',
            'src/util/serialization.test.js'
        ],
        plugins: [
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-ie-launcher',
            'karma-mocha',
            'karma-chai',
            'karma-webpack'
        ],
        frameworks: ['mocha', 'chai'],
        port: 9876,
        colors: false,
        logLevel: config.LOG_DEBUG,
        autoWatch: false,
        preprocessors: {
            'src/util/zet.js': ['webpack'],
            'src/util/zet.test.js': ['webpack'],
            'src/util/serialization.js': ['webpack'],
            'src/util/serialization.test.js': ['webpack']
        },

        webpack: webpackConfig,
        webpackMiddleware: {
            noInfo: false
        },
        singleRun: false,
        concurrency: Infinity,
    });
};
@nitinsurana
Copy link
Author

Possible duplicate of #243

@nitinsurana
Copy link
Author

nitinsurana commented Jan 24, 2018

Fix is same as mentioned here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant