Webpack尽管存在于webpack.config.js中,但未能使用babel-loader

时间:2015-09-02 01:03:11

标签: webpack babeljs

我有一个奇怪的问题,即使在我的webpack.config.js文件中正确引用了babel-loader,它仍被完全忽略。

错误是:

Hash: d9f2eead3307d16f76f3
Version: webpack 1.12.0
Time: 37ms
    + 1 hidden modules

ERROR in ./src/index.js
Module parse failed: D:\Dropbox\Work\node_modules\cycle-apptools\src\index.js Line 3: Unexpected token
You may need an appropriate loader to handle this file type.
| var x = `hello${1}`;
|
| import foo from './foo';
|
| function run() {

我的webpack.config.js文件如下所示:

module.exports = {
  entry: './src/index.js',
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loader: 'babel',
        exclude: /node_modules/
      }
    ]
  },
  output: {
    path: './dist',
    filename: 'index.js',
    sourceMapFilename: 'index.js.map'
  },
  devtool: '#source-map'
};

我安装了以下npm软件包:

"babel-core": "^5.8.23",
"babel-loader": "^5.3.2",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.1",
"gulp-concat": "^2.6.0",
"gulp-sourcemaps": "^1.5.2",
"webpack": "^1.12.0"

我的index.js文件如下所示:

var x = `hello${1}`;

import foo from './foo';

function run() {
  console.log('foo:', foo.foo);
  throw new Error('AppTools run is not yet implemented');
}

export default {
  run
}

...和foo.js看起来像这样:

export default {
  foo: 1
};

最后,这是我的目录结构,由崇高的文字提供:

enter image description here

为什么webpack忽略了babel loader?

1 个答案:

答案 0 :(得分:1)

发现问题。我正在我的dev根目录中的node_modules文件夹中开发,这样我就可以在我的本地项目中测试我的自定义模块,而不必在每次进行更改时都重新部署到npm。排除模式正在过滤掉我的源文件。