Skip to content Skip to sidebar Skip to footer

Webpack And AngularJs

I'm trying to run simple app with angularjs and webpack , here is my code : index.html

Solution 1:

bundle.js is generated by webpack so I think that you don't need to write this file.

The correct name for Webpack config file is webpack.config.js. With this file in place you can launch compilation with webpack or webpack --watch to continuously compile you bundle file as you modify your code.

I've create a angular-index.js to wrap Angular as CommonJS module. Here is the source code :

require('./angular.min.js');
module.exports = angular;

And I've merged main.js and 'app.js' in one single file

var jquery = require('jquery');
var angular = require('./angular-index');

var myApp = angular.module('myApp', []);
myApp.controller('mainCtrl', require('./mainCtrl'));

And finally, I've added mainCtrl.js. This one is just the function definition of the controller.

module.exports = function($scope) {
  $scope.firstName = 'John';
  $scope.lastName = 'Doe';
};

For better and detailed explication please read this blog post https://blog.codecentric.de/en/2014/08/angularjs-browserify/. My working code is here https://github.com/jean-rakotozafy/angular-webpack-template


Post a Comment for "Webpack And AngularJs"