webpack Usage AMD modules example


Example

Create folder. Open it in command line. Run npm install webpack -g. Create 2 files:

cats.js:

define(function(){
    return ['dave', 'henry', 'martha'];
});

app.js

require(['./cats'],function(cats){
    console.log(cats);
})

Run in command line:

webpack ./app.js app.bundle.js

Now in folder will be file: app.bundle.js.

Create index.html file:

<html>
    <body>
        <script src='app.bundle.js' type="text/javascript"></script>
    </body>
</html>

Open it in browser and see result in console:

[ 'dave', 'henry', 'martha' ]