如何让webpack编译app / js目录中的main.js文件?

时间:2016-08-25 13:03:19

标签: javascript node.js reactjs

我在这里撕开我的头发,我正在尝试创建一个Reactjs应用程序。我创建了文件夹然后执行:

npm install webpack -g

然后我执行了:

npm init

完成package.json文件:

{
  "name": "reactquiz",
  "version": "1.0.0",
  "description": "This is a Reactjs quiz app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Daniel Cortes",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "6.13.*",
    "babel-loader": "6.2.*",
    "webpack": "^1.13.2"
  },
  "dependencies": {
    "react": "^15.3.1",
    "react-dom": "^15.3.1"
  }
}

然后我在本地执行webpack:

npm install webpack --save-dev

然后我创建了webpack.config.js文件:

module.export = {
    entry: [
        './src/index.js'
    ],
    output: {
        path: __dirname,
        filename: 'app/js/main.js'
    },
    module: {
        loaders: [{
            test: /\.jsx?$/,
            loader: 'babel-loader',
            exclude: /node_modules/
        }]
    }

}

我意识到我在app / js中仍然没有main.js文件。请帮忙。我看过webpack文档,我看过这里,我看过教程。安装webpack的正确方法是什么,以便在app / js / main.js中生成文件?

1 个答案:

答案 0 :(得分:0)

文件名看起来不正确,格式正确为:

filename: './app/js/main.js'

此外,您没有“执行webpack”,而是安装了它。之后你也执行了命令webpack吗?