webpack执行出错了。

查看:106
本文介绍了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,出错了,为什么?

解决方案

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下查找

这篇关于webpack执行出错了。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆