2016-11-27 101 views
0

我刚刚刚接触webpack并作出反应,只是通过文档并创建了一个示例来工作。不幸的是我卡住了,无法继续。问题是没有生成捆绑文件。 我创建的文件是未生成Webpack捆绑文件

的package.json

{ 
    "name": "rohith", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "start": "webpack-dev-server" 
    }, 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "react": "^15.4.1", 
    "react-dom": "^15.4.1", 
    "webpack": "^1.13.3", 
    "webpack-dev-server": "^1.16.2" 
    } 
} 

webpack.config.js

module.export = { 
    entry : './main.js', 
    output : { 
     path : './', 
     filename : 'index.js' 
    }, 
    devServer : { 
     inline : true, 
     port : 3333 
    }, 
    module : { 
     loaders : [ 
      { 
       test : /\.js$/, 
       exclude : /node_modules/, 
       loader : 'babel', 
       query : { 
        presets : ['es2015','react'] 
       } 
      } 
     ] 
    } 
} 

App.js

import React from 'react'; 
class App extends React.Component { 
    render(){ 
     return <div>Hello</div> 
    } 
} 

export default App 

main.js

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import App from './App'; 
ReactDOM.render(<App />,document.getElementById('app')); 

的index.html

<!DOCTYPE html> 
<html lang = "en"> 
<head> 
    <meta charset = "UTF-8"> 
    <title>Setup</title> 
</head> 
<body> 
    <div id = "app"></div> 
    <script src ="index.js"></script> 
</body> 
</html> 

我得到那个包是有效的,但不产生index.js。 不能在本地主机3333

由于运行,

回答

1

在webpack.config.js,使用module.exports代替module.export。请参阅Output filename not configured Error in Webpack 另请注意,您的package.json缺少一些依赖关系。这是更新的package.json,它的工作原理:

{ 
"name": "rohith", 
"version": "1.0.0", 
"description": "", 
"main": "index.js", 
"scripts": { 
    "start": "webpack-dev-server" 
}, 
"author": "", 
"license": "ISC", 
"dependencies": { 
    "react": "^15.4.1", 
    "react-dom": "^15.4.1", 
    "webpack": "^1.13.3", 
    "webpack-dev-server": "^1.16.2" 
}, 
"devDependencies": { 
    "babel": "^6.5.2", 
    "babel-core": "^6.18.2", 
    "babel-loader": "^6.2.8", 
    "babel-preset-es2015": "^6.18.0", 
    "babel-preset-react": "^6.16.0" 
} 
} 
6

我认为问题是,你没有给绝对的输出路径。

试试这个:

var path = require('path'); 

module.exports = { 
    entry : './main.js', 
    output : { 
     path : path.join(__dirname, './'), 
     filename : 'index.js' 
    }, 
    devServer : { 
     inline : true, 
     port : 3333 
    }, 
    module : { 
     loaders : [ 
      { 
       test : /\.js$/, 
       exclude : /node_modules/, 
       loader : 'babel', 
       query : { 
        presets : ['es2015','react'] 
       } 
      } 
     ] 
    } 
} 

希望它能帮助:)

2

替换你的脚本与以下对象:

"scripts": { 
    "start": "npm run build", 
    "build": "webpack -p && webpack-dev-server" 
    }, 

然后,运行$ npm start

0

对我的问题与“脚本”下的package.json一起

这里是修复:

里面你的package.json文件,脚本下增加以下内容:

“脚本”:{
“开始”: “的WebPack-dev的服务器”,
“建”: “的WebPack -p” }

首先,我跑了构建然后开始。

纱建立

,如果你先建那么你bundle.js文件将被创建之后,你可以使用这个命令:

纱线开始