sologgfun
V2EX  ›  问与答

rollup 打包不支持 async 语法吗?

  •  
  •   sologgfun · Oct 19, 2020 · 1451 views
    This topic created in 2044 days ago, the information mentioned may be changed or developed.

    入口文件 index.js

    const { determineRepoDir } = require('./expo');
    
    console.log(determineRepoDir)
    

    expo.js

    const { mark } = require('../lib/profile');
    async function fff() {
      console.log('11')
    }
    

    现象就是如果 expo.js 的 fff 函数不带 async 头,那么 profile 文件里面的代码就会被打包起来,否则不会打包,只会保留 require 的代码?

    自己看了半天没整出来为啥。。

    5 replies    2020-10-23 10:09:58 +08:00
    Geo200
        1
    Geo200  
       Oct 19, 2020
    你可能需要个解析 async 的插件: https://github.com/leebyron/rollup-plugin-async
    sologgfun
        2
    sologgfun  
    OP
       Oct 19, 2020
    @Geo200 应该不是的,我加了 ployfill 之后还是不行,直接不管加不加 async,都不会打包 profile 文件了
    DingSoung
        3
    DingSoung  
       Oct 22, 2020
    同问 await 也不支持
    sologgfun
        4
    sologgfun  
    OP
       Oct 22, 2020
    @DingSoung 加个 babel 插件吧,这个问题我已经大概整明白了;
    之所以没有打包,是因为 commonjs 插件判断当前文件是 es6 模块,所以没有进行解析,可以通过一个参数 mix 啥的我记不清了,设定为 es6 和 cjs 混合的模块,才会进行解析,但是设定为混合模块后有时候还是有问题,我 github 提 issue 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   947 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:06 · PVG 04:06 · LAX 13:06 · JFK 16:06
    ♥ Do have faith in what you're doing.