V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
sologgfun
V2EX  ›  问与答

rollup 打包不支持 async 语法吗?

  •  
  •   sologgfun · 2020-10-19 16:29:26 +08:00 · 1038 次点击
    这是一个创建于 1278 天前的主题,其中的信息可能已经有所发展或是发生改变。

    入口文件 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 条回复    2020-10-23 10:09:58 +08:00
    Geo200
        1
    Geo200  
       2020-10-19 16:39:05 +08:00
    你可能需要个解析 async 的插件: https://github.com/leebyron/rollup-plugin-async
    sologgfun
        2
    sologgfun  
    OP
       2020-10-19 16:47:42 +08:00
    @Geo200 应该不是的,我加了 ployfill 之后还是不行,直接不管加不加 async,都不会打包 profile 文件了
    DingSoung
        3
    DingSoung  
       2020-10-22 17:30:28 +08:00
    同问 await 也不支持
    sologgfun
        4
    sologgfun  
    OP
       2020-10-22 21:19:45 +08:00
    @DingSoung 加个 babel 插件吧,这个问题我已经大概整明白了;
    之所以没有打包,是因为 commonjs 插件判断当前文件是 es6 模块,所以没有进行解析,可以通过一个参数 mix 啥的我记不清了,设定为 es6 和 cjs 混合的模块,才会进行解析,但是设定为混合模块后有时候还是有问题,我 github 提 issue 了
    DingSoung
        5
    DingSoung  
       2020-10-23 10:09:58 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5093 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:33 · PVG 17:33 · LAX 02:33 · JFK 05:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.