How to compile a project properly with Babel and Grunt

前端 未结 3 1456
情话喂你
情话喂你 2021-01-30 11:26

I\'m trying to play with Babel, but it doesn\'t work well for me.

My project is simple

|-project/
|---src/
|-----index.html
|-----main.js
|-----module.js         


        
3条回答
  •  萌比男神i
    2021-01-30 11:38

    First, the browser say require is not defined, so I add require.js to my HTML.

    I don't think, that adding require.js will be the solution. In this context require is node-style syntax: (https://github.com/substack/browserify-handbook#user-content-require).

    Browserify is a module loader but works different than requirejs. There is a babel distribution for requirejs, too (https://github.com/mikach/requirejs-babel) but I recommend using browserify.

    In a setup, where babel is working with browserify, something like this

    import $ from'jquery';
    

    will become something like this

    var $ = require('jquery');
    

提交回复
热议问题