Webpack 2 compiling but not running javascript -


i have 2 js files

index.js

const sum = require('./app');  const total = sum(10,5);  console.log(total); 

app.js

function sum(a,b){   return a+b; } module.exports = sum; 

webpack config

const path = require('path');  const config ={   entry:"./app/index.js",   output:{     path:path.resolve(__dirname,"app/build"),     filename:'bundle.js'   } }  module.exports = config; 

the bundle.js getting generated , have added bundle index.html, bundle gets loaded when checking in network tab. console.log(total) not working, nothing works.

nothing showed in browser console? errors? maybe better show configuration ( eg: webpack command or/and package.json )?

your code works fine configuration :

enter image description here

app ├── app.js ├── build │   ├── bundle.js │   └── index.html └── index.js 

webpack.config.js :

const path = require('path');  const config ={   entry:"./app/index.js",   output:{     path:path.resolve(__dirname,"app/build"),     filename:'bundle.js'   } }  module.exports = config; 

package.json :

{   "name": "stackof",   "version": "1.0.0",   "description": "",   "main": "index.js",   "scripts": {     "dev": "webpack -d --watch"   },   "author": "marwen <marwen109@gmail.com> (http://www.gameole.com)",   "license": "isc",     "devdependencies": {     "webpack": "2.2.1"   } } 

index.html :

<!doctype html> <html>   <head>     <title>title webpack</title>   </head>   <body>     <div id="root"></div>   <script type="text/javascript" src="bundle.js"></script></body> </html> 

to generate bundle need execute :

npm run dev 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -