webpack执行出错了。

如下图为我的项目结构:
dist 存放webpack打包后的文件
src 存放原始文件

项目解构

package.json的代码为:

{
        "name": "webpack2",
        "version": "1.0.0",
        "description": "",
        "main": "index.js",
        "scripts": {
                "test": "echo \"Error: no test specified\" && exit 1"
        },
        "keywords": [],
        "author": "",
        "license": "ISC",
        "dependencies": {
                "babel-polyfill": "^6.16.0",
                "jquery": "^3.1.1",
                "mustache": "^2.2.1"
        },
        "devDependencies": {
                "babel-core": "^6.18.0",
                "babel-loader": "^6.2.7",
                "babel-preset-es2015": "^6.18.0",
                "webpack": "^1.13.3"
        }
}

配置文件为:

module.exports = {
    entry: 'src/entry.js',
    output: {
        path: 'dist',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.css$/,
                loader: 'style!css'
            }
        ]
    }
};

问题来了,执行webpack,出错了,为什么?
图片描述

阅读 3.4k
3 个回答
module.exports = {
    entry: './src/entry.js',
    output: {
        path: 'dist',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.css$/,
                loader: 'style!css'
            }
        ]
    }
};

entry 为 ./src/entry,这样会在当前目录查找
你写的 src/entry ,会去node_modules下查找

你那个'sr**'的模块没有找到 安装下

我觉得应该跟babel有关
我是这样设置的,没有问题

{
    test: /\.js$/,
    loader: 'babel',
    query: {
      presets: ['es2015'],
      plugins: ['transform-runtime']
    },
    exclude: /node_modules/
  }
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.14.0",
"babel-runtime": "^6.11.6",
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题