首页 > webpack配置babel

webpack配置babel

var path = require('path');
module.exports = {
    entry: './app/index.js',
    output: {
        path: './build/',
        filename: 'build.js'
    },

    module: {
        loaders: [
            {
                test: /\.css$/,
                loaders: ["style", "css"],
                exclude: "/node_modules/"
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: "/node_modules/",
                query: {
                    presets: ['es2015']
                }
            }
        ]
    },

    resolve: {
        extensions: ['', '.js', '.css']
    }

}

会报出错误.

ERROR in C:/Documents and Settings/Neko/Application Data/npm/~/webpack-dev-serve
r/client?http://localhost:8080
Module not found: Error: Cannot resolve module 'babel-loader' in C:\Documents an
d Settings\Neko\Application Data\npm\node_modules\webpack-dev-server\client
 @ C:/Documents and Settings/Neko/Application Data/npm/~/webpack-dev-server/clie
nt?http://localhost:8080 1:10-24

ERROR in C:/Documents and Settings/Neko/Application Data/npm/~/webpack-dev-serve
r/client?http://localhost:8080
Module not found: Error: Cannot resolve module 'babel-loader' in C:\Documents an
d Settings\Neko\Application Data\npm\node_modules\webpack-dev-server\client
 @ C:/Documents and Settings/Neko/Application Data/npm/~/webpack-dev-server/clie
nt?http://localhost:8080 3:16-37

ERROR in C:/Documents and Settings/Neko/Application Data/npm/~/webpack-dev-serve
r/client?http://localhost:8080
Module not found: Error: Cannot resolve module 'babel-loader' in C:\Documents an
d Settings\Neko\Application Data\npm\node_modules\webpack-dev-server\client
 @ C:/Documents and Settings/Neko/Application Data/npm/~/webpack-dev-server/clie
nt?http://localhost:8080 2:13-37

.. 我之前加上了include: [path.resolve(__dirname, "/app/")], 能够完成编译, 但是babel没有起作用.. 请问....是哪里出问题了..


你没装babel-loader,来吧:

npm install --save-dev babel-core babel-loader

好像是没有安装babel-loader,检查下node_modules目录下面有没有babel-loader目录,确定一下package.json里面有没有添加依赖。

"dependencies": {
    //...
    "babel-core": "^6.6.0",
    "babel-loader": "^6.2.4",
    //...
【热门文章】
【热门文章】