Webpack babel-loader doesn't transpile imported .js files

倾然丶 夕夏残阳落幕 提交于 2019-12-11 12:46:05

问题


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')]
          }, (...)

来源:https://stackoverflow.com/questions/52016829/webpack-babel-loader-doesnt-transpile-imported-js-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!