VueJS应用程序无法在Internet Explorer上加载

时间:2018-11-12 16:46:32

标签: javascript vue.js webpack cross-browser babeljs

我一直在IE上收到此错误:

  

SCRIPT1010:预期的标识符bundle.js

我找到了一个名为targets-webpack-plugin的模块形式的解决方案,该模块的工作原理像一个超级按钮,但同时在我的应用程序上造成了新问题。每当我尝试通过sourcemap在Google Chrome上调试时,它不会显示包含错误的文件的源,而是显示如下:

  

ReferenceError:未定义父母       在deserializeParent(bundle.js:16180)       在bundle.js:16192

sourcemaps似乎无法正常运行。这将是预期的输出:

  

ReferenceError:未定义父母       在deserializeParent(account.ts:44)       在account.ts:117

现在删除targets-webpack-plugin将使我回到不在IE上运行我的应用程序的问题。这是我的webpack配置:

module.exports = {
  context: path.dirname(__dirname),
  entry: {
    app: './src/main.js',
  },
  target: 'web',

  output: {
    filename: '[name].[contenthash].js',
    hashDigestLength: 8,
  },

  resolve: {
    extensions: ['.ts', '.js', '.vue'],
    alias: {
      '@': path.resolve(__dirname, '../src'),
    },
  },

  module: {
    rules: [
      {
        test: /\.js/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
          },
          {
            loader: 'ts-loader',
            options: {
              transpileOnly: true,
            },
          },
        ],
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
        ],
      },
      {
        test: /\.scss$/,
        use: [
          'style-loader',
          'css-loader',
          'sass-loader',
        ],
      },
    ],
  },

  stats: 'errors-only',

  plugins: [
    new VueLoaderPlugin(),
    new ForkTsCheckerWebpackPlugin({
      tslint: true,
      reportFiles: ['src/**/*.ts'],
    }),
    new StylishWebpackPlugin(),
    new webpack.DefinePlugin({
      USE_LOGROCKET: withLogRocket,
    }),
    // new TargetsPlugin({
    //   browsers: ['last 2 versions', 'chrome >= 41', 'not ie <= 8', '> 1%'],
    // }),
  ],
};

上面是基本的webpack配置,而这是我的dev webpack配置:

module.exports = merge(baseConfig, {
  mode: 'development',

  devtool: 'source-map',
  output: {
    filename: 'bundle.js',
    publicPath: 'https://localhost:8080/',
  },

  module: {
    rules: [
      {
        test: /\.(png|jpe?g|gif|webp)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 4096,
              name: 'img/[name].[hash:8].[ext]',
            },
          },
        ],
      },
    ],
  },
});

最后这是我的.babelrc文件:

{
    "presets": ["env"],
    "plugins": [
        "transform-es2015-destructuring",
        "transform-object-rest-spread"
    ]
}

我尝试thisthis无济于事。我尝试根据上述链接中的建议更改babelrc文件,但由于该文件不起作用,我不得不还原。我也尝试过es3ify,但在编译代码时,似乎 spread必须是元素列表的最后一个元素。我还尝试使用 babel-polyfill ,但没有雪茄,所以我不得不恢复到原始的webpack配置。我的index.html文件中也已经有<meta name="viewport" content="width=device-width, initial-scale=1">,但似乎也没有帮助。有没有一种方法可以解决IE问题,同时又不破坏Sourcemap(在Chrome上)?是否有任何节点模块或配置上的某些更改可以帮助我?

编辑:我也尝试了babel-preset-env,但是也没有用。

编辑:在IE 11上进行了测试

0 个答案:

没有答案