使用Webpack的解析模块时,Babel不会转换代码

时间:2016-12-29 13:43:22

标签: webpack babeljs webpack-2

左右似乎,

如果我使用常规相对路径,代码会转换,但是当我使用resolve.modules时,我会收到以下错误消息:

You may need an appropriate loader to handle this file type.
| export default class Test {
|
|     name = 'Joe';
|
|     constructor() {
      ...

webpack.config:

...
resolve: {
    modules: [
        path.resolve(__dirname,'resources/assets/app'),
        path.resolve('./node_modules')
    ],
},

module: {
...

应用程序/核心/ Test.js:

export default class Test {

    name = 'Joe';

    constructor() {
        console.log('construct a Test');
    }
}

用法:

import Test from 'core/Test';

有谁知道这是一个错误还是我错过了什么?

使用resolve.alias

时出现同样的错误

还尝试使用babel-plugin-transform-class-properties

.babelrc

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ],
  "plugins": [
    "babel-plugin-transform-class-properties",
    "react-hot-loader/babel",
    "transform-async-to-generator",
    "transform-decorators-legacy"
  ]
}

0 个答案:

没有答案