how to set up grunt + browserify + tsify + babelify?

我与影子孤独终老i 提交于 2020-01-04 06:09:27

问题


I am struggling to set up grunt + browserify + tsify + babelify (with debug).

The below gruntfile setting does compile typescript, but no babel transpling is happening.

Can anybody let me know how to do this? (i might need to use gulp to do this??)

        browserify: {
        main: {
            src: 'app/scripts/main.ts',
            dest: 'app/scripts/bundle.js',
        },
        options: {
            browserifyOptions: {
                plugin: [['tsify']],
                transform: [['babelify', {presets: ['es2015'], extensions: ['.ts']}]],
                debug: true
            }
        }
    }

tsconfig.json has target set to 'es2015'.


回答1:


The problem is that grunt-browserify loads the transforms first and then the plugins, so what you want to do - put the transform after the plugin - is not possible with a declarative configuration.

However, you can use the grunt-browserify configure function and set up the plugin and transform inside said function:

browserify: {
    main: {
        src: 'app/scripts/main.ts',
        dest: 'app/scripts/bundle.js',
    },
    options: {
        browserifyOptions: {
            debug: true
        },
        configure: function (bundler) {

            bundler.plugin(require('tsify'));
            bundler.transform(require('babelify'), {
                presets: ['es2015'],
                extensions: ['.ts']
            });
        }
    }
}


来源:https://stackoverflow.com/questions/40182786/how-to-set-up-grunt-browserify-tsify-babelify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!