Webpack babel-loader doesn't transpile importe

2019-07-28 12:08发布

问题:

My VueJS app doesn't render correctly in IE11 (polyfills are being applied though).

I discovered that this is caused by several JS files I imported into my project, which apparantly aren't transpiled by babel. And indeed, when I manually transpile these files (babel-cli) and import the transpiled version, the problem is resolved.

However, these files should be transpiled by automatically, just like the rest of my project.

How can I solve this issue?

import example

import depth from '@/functions/depth'

('@' is resolved by webpack. Path is correct)

My .babelrc file (originally from vue webpack boilerplate)

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-vue-jsx", "transform-runtime"]
}

webpack config (originally from vue webpack boilerplate)

 module: {
        rules: [
          {
            test: /\.js$/,
            loader: 'babel-loader',
            include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
          }, (...)