Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在nuxt中使用babel polyfill(而不是polyfill.io)_Javascript_Webpack_Babeljs_Nuxt.js - Fatal编程技术网

Javascript 在nuxt中使用babel polyfill(而不是polyfill.io)

Javascript 在nuxt中使用babel polyfill(而不是polyfill.io),javascript,webpack,babeljs,nuxt.js,Javascript,Webpack,Babeljs,Nuxt.js,我正在用nuxt vuetify模板构建一个静态站点,虽然它非常棒,并且提供了很多已经为我完成的配置和设置,但我发现要使我的站点在Internet Explorer上平稳运行确实很困难(11) 由于ES6代码需要传输,我正在尝试在我的应用程序中配置babel,这是我第一次体验配置babel(因此,请忽略我在该领域的知识不足)。互联网上有太多的问题,我几乎都试过了,但都没有成功 TL;DR,我正在使用Nuxt 2.x(以及Webpack 4,内部),我不知道在哪里以及如何包含@babel/poly

我正在用nuxt vuetify模板构建一个静态站点,虽然它非常棒,并且提供了很多已经为我完成的配置和设置,但我发现要使我的站点在Internet Explorer上平稳运行确实很困难(11)

由于ES6代码需要传输,我正在尝试在我的应用程序中配置babel,这是我第一次体验配置babel(因此,请忽略我在该领域的知识不足)。互联网上有太多的问题,我几乎都试过了,但都没有成功

TL;DR,我正在使用Nuxt 2.x(以及Webpack 4,内部),我不知道在哪里以及如何包含
@babel/polyfill
,因为

  • 我们在Nuxt应用程序中没有定义或明确的入口点,在那里我可以导入文件
    import'@babel.polyfill'
    ,如许多地方所述,包括babel官方文档

  • Webpack4也没有
    条目。vendor
    字段,我可以在其中注入polyfill

  • 这是我的numxt.config.js

    babel: {
          presets: [
            ['@babel/preset-env', {
              'useBuiltIns': 'usage',
              'targets': '> 0.25%, not dead'
            }]
          ],
          plugins: ['@babel/plugin-syntax-dynamic-import', [
            '@babel/plugin-transform-runtime',
            {
              'corejs': false,
              'helpers': true,
              'regenerator': true,
              'useESModules': false
            }
          ]],
          'configFile': false,
          'babelrc': false
    }
    
    以下是我正在使用的软件包的版本:

    "dependencies": {
        "@babel/polyfill": "^7.2.5"
    }
    
    "devDependencies": {
        "@babel/core": "^7.2.2",
        "@babel/plugin-transform-runtime": "^7.2.0",
        "@babel/preset-env": "^7.2.3",
        "@babel/runtime-corejs2": "^7.3.0",
        "babel-core": "^6.26.3",
        "babel-eslint": "^10.0.1",
        "babel-loader": "^8.0.5",
        "babel-plugin-dynamic-import-node": "^2.2.0"
    }
    
    
    接下来,我还想将
    babel polyfill
    作为供应商推送到webpack entry对象,但它给了我一个错误:
    无法设置未定义的属性“vendor”,因为显然,webpack 4 configs没有一个条目字段,就像webpack 3以前的条目字段一样

    这是我的webapack配置:

    { 
      name: 'client',                                                                                                                                                                                 
      mode: 'production',
      devtool: false,
      optimization: 
       { runtimeChunk: 'single',
         minimize: true,
         minimizer: undefined,
         splitChunks: 
          { chunks: 'all',
            automaticNameDelimiter: '.',
            name: undefined,
            cacheGroups: [Object] } },
      output: 
       { path: '/home/waleed/project/.nuxt/dist/client',
         filename: '[chunkhash].js',
         chunkFilename: '[chunkhash].js',
         publicPath: '/_nuxt/' },
      performance: { maxEntrypointSize: 1024000, hints: 'warning' },
      resolve: 
       { extensions: [ '.wasm', '.mjs', '.js', '.json', '.vue', '.jsx' ],
         alias: 
          { '~': '/home/waleed/project',
            '~~': '/home/waleed/project',
            '@': '/home/waleed/project',
            '@@': '/home/waleed/project',
            assets: '/home/waleed/project/assets',
            static: '/home/waleed/project/static' },
         modules: 
          [ 'node_modules',
            '/home/waleed/projectnode_modules',
            '/home/waleed/project/node_modules/@nuxt/config/node_modules' ] },
      resolveLoader: 
       { modules: 
          [ 'node_modules',
            '/home/waleed/project/node_modules',
            '/home/waleed/project/node_modules/@nuxt/config/node_modules' ] },
      module: 
       { rules: 
          [ [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object],
            [Object] ] },
      plugins: 
       [ VueLoaderPlugin {},
         WarnFixPlugin {},
         WebpackBarPlugin {
           profile: false,
           handler: [Function],
           modulesCount: 500,
           showEntries: false,
           showModules: true,
           showActiveModules: true,
           options: [Object],
           reporters: [Array] },
         MiniCssExtractPlugin { options: [Object] },
         HtmlWebpackPlugin { options: [Object] },
         HtmlWebpackPlugin { options: [Object] },
         VueSSRClientPlugin { options: [Object] },
         DefinePlugin { definitions: [Object] } ] 
    }
    

    注:我已经看过并尝试过了,它肯定也有一定的效果,但我的用例要求不要使用polyfill.io。

    对于所有这些人,像我一样敲打他们的脑袋,(作为一个临时解决方案),我决定使用babel polyfill,并将其url包含在
    nuxt.config.js
    文件的脚本部分,如下所示

    script: [
          { src: 'https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.2.5/polyfill.min.js' }
        ]
    
    但是,我仍在寻找更干净、更具ES6ish的
    import
    require
    语法,以实现所需的结果。因此,如果您有这样的解决方案,请随意添加更多答案