vue cli webpack打破了IE10

时间:2018-01-29 09:42:25

标签: webpack vue-cli

现在我正在使用带有webpack配置的vue-cli,这在Internet Explorer 10上遇到了麻烦。问题是webpack没有将letconst转换为{{ 1}}和IE 10不支持varlet等ES5变量。

以下是const代码。

webpack.base.conf.js

编译后的代码会在IE10上用以下行引发错误module.exports = { context: path.resolve(__dirname, '../'), entry: { app: ['babel-polyfill','./src/main.js'], }, output: { path: config.build.assetsRoot, filename: '[name].js', publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath }, resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), } }, module: { rules: [ ...(config.dev.useEslint ? [createLintingRule()] : []), { test: /\.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test')] }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('media/[name].[hash:7].[ext]') } }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } } ] }, node: { // prevent webpack from injecting useless setImmediate polyfill because Vue // source contains it (although only uses it if it's native). setImmediate: false, // prevent webpack from injecting mocks to Node native modules // that does not make sense for the client dgram: 'empty', fs: 'empty', net: 'empty', tls: 'empty', child_process: 'empty' } }

  

...让a = ...

但是,我所知道的是,webpack基本上将SCRIPT1002let转换为const,但结果却没有。我怎么强迫变换?

1 个答案:

答案 0 :(得分:1)

问题是...... 不是vue本身,而是node_modules中的包。其中一个包基本上没有被编译(在我的例子中,buefy库),所以我必须手动编译。

<强>解决方案

webpack.base.conf.js

  • 将buefy添加到转换条目中(据我所知,vue-cli webpack会忽略node_modules中的包以解决性能问题)。

    {
      test: /\.js$/,
      loader: 'babel-loader',
      include: [/node_modules\/buefy/, resolve('src'), resolve('test')]
    },
    
  • 添加新别名以导入手动转换的包。

    resolve: {
      extensions: ['.js', '.vue', '.json'],
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': resolve('src'),
        'buefy$': resolve('node_modules/buefy/src'),
      }
    }