代码之家  ›  专栏  ›  技术社区  ›  Fuzzyma

巴别塔填充物包括所有填充物,无论设置了哪个目标

  •  0
  • Fuzzyma  · 技术社区  · 8 年前

    我在使用Babel7.1和rollup(v0.67)。这是我的汇总配置:

    {
      input: 'src/svg.js',
      output: {
        file: 'dist/myBundle.js',
        name: 'myBundle',
        sourceMap: true,
        format: 'iife'
      },
      plugins: [
        resolve({browser: true}),
        commonjs(),
        babel({
          include: 'src/**',
          runtimeHelpers: true,
          babelrc: false,
          presets: [["@babel/preset-env", {
            modules: false,
            targets: {
              firefox: "63"
            },
            useBuiltIns: "usage"
          }]],
          plugins: [["@babel/plugin-transform-runtime", {
            corejs: false,
            helpers: true,
            regenerator: true,
            useESModules: true
          }]]
        })
      ]
    }
    

    我想多填充旧的浏览器。根据文件,我需要包括 babel-polyfill 在我的切入点,我做到了。现在巴贝尔应该只包括所需的填充物(因为 useBuiltIns: "usage" ). 然而,即使指定最新的浏览器作为目标, 我把所有的代码都放进包里 (10000行代码)。

    我试过的:

    • 我试过了 useBuiltIns: "entry" 它为更新的浏览器修复了这个问题,但这不是我想要的(它只包括所有的polyfill 潜在的 浏览器需要的,无论它们是否在代码中实际使用)。

    • 更改汇总插件的顺序

    • 不包括 巴别塔聚脂 进口

    我不知道为什么会这样。如果有人能解决这个问题,那就太好了。它把我逼疯了!

    如果有人知道为什么没有生成sourcemap,我也不介意得到答案

    1 回复  |  直到 8 年前
        1
  •  1
  •   mattpilott    7 年前

    嘿,我做了一个repo,它探索了一个好的babel/rollup设置,使用预设env和useBuiltIns'usage'。

    // Rollup plugins
    import babel from 'rollup-plugin-babel';
    import commonjs from 'rollup-plugin-commonjs';
    import resolve from 'rollup-plugin-node-resolve';
    
    export default {
        input : 'main.js',
        output : {
            file : 'app.js',
            format : 'iife',
            name : 'PROJECT'
        },
        plugins : [
            resolve(),
            babel({
                exclude : 'node_modules/**',
                presets : [[
                    '@babel/env', {
                        useBuiltIns : 'usage'
                    }
                ]],
                plugins : [
                    '@babel/plugin-transform-runtime'
                ],
                runtimeHelpers : true
            }),
            commonjs()
        ]
    };
    

    看一看 https://github.com/matt3224/rollup-babel7

    如果你能找出如何进一步减少输出提交一个PR

    推荐文章