Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack bundled file not generated

I am just new to webpack and react , just going through the docs and created a example to work. Unfortunately i got stuck and not able to proceed . Th problem is the bundled file is not generated. The files i created is

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>

I am getting that bundle is valid, but no index.js is generated. can't run in localhost 3333

Thanks,

like image 637
Krishna Avatar asked Nov 27 '16 07:11

Krishna


2 Answers

I think the problem is that you are not giving the absolute output path.

Try this:

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']
                }
            }
        ]
    }
}

Hope it helps :)

like image 93
Swapnil Avatar answered Oct 26 '22 18:10

Swapnil


In webpack.config.js, use module.exports instead of module.export. See Output filename not configured Error in Webpack Also be noticed that your package.json lacks some dependencies. Here is the updated package.json that works:

{
"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"
}
}
like image 45
ntahoang Avatar answered Oct 26 '22 19:10

ntahoang