Skip to content

Commit

Permalink
Setup webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
smashdevcode committed Mar 2, 2016
1 parent cbb9134 commit d18e144
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
vendor.bundle.js
todo.bundle.js
9 changes: 9 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

var angular = require('angular');

angular.module('todoListApp', []);

require('./scripts/services');
require('./scripts/directives');
require('./scripts/controllers');
6 changes: 6 additions & 0 deletions app/scripts/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

var angular = require('angular');

angular.module('todoListApp').controller('mainCtrl', require('./main'));
angular.module('todoListApp').controller('todoCtrl', require('./todo'));
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';

angular.module('todoListApp')
.controller('mainCtrl', function($scope, dataService){
function MainCtrl ($scope, dataService) {

dataService.getTodos(function(response){
var todos = response.data.todos;
$scope.todos = todos;
});
});

$scope.addTodo = function() {
$scope.todos.unshift({name: "This is a new todo.",
completed: false});
};

})
}

module.exports = MainCtrl;
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
'use strict';

angular.module('todoListApp')
.controller('todoCtrl', function($scope, dataService) {
function TodoCtrl ($scope, dataService) {

$scope.deleteTodo = function(todo, index) {
$scope.todos.splice(index, 1);
dataService.deleteTodo(todo);
};

$scope.saveTodos = function() {
var filteredTodos = $scope.todos.filter(function(todo){
if(todo.edited) {
return todo
};
})
dataService.saveTodos(filteredTodos);
};
});
};

}

module.exports = TodoCtrl;
5 changes: 5 additions & 0 deletions app/scripts/directives/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var angular = require('angular');

angular.module('todoListApp').directive('todo', require('./todo'));
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

angular.module('todoListApp')
.directive('todo', function(){
function ToDoDirective () {
return {
templateUrl: 'templates/todo.html',
replace: true,
controller: 'todoCtrl'
}
});
}

module.exports = ToDoDirective;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('todoListApp')
.service('dataService', function($http) {
function DataService ($http) {

this.getTodos = function(cb) {
$http.get('/api/todos').then(cb);
};
Expand All @@ -14,4 +14,6 @@ angular.module('todoListApp')
console.log("I saved " + todos.length + " todos!");
};

});
}

module.exports = DataService;
5 changes: 5 additions & 0 deletions app/scripts/services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var angular = require('angular');

angular.module('todoListApp').service('dataService', require('./data'));
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"homepage": "https://github.com/treehouse/mean-todo#readme",
"dependencies": {
"angular": "^1.4.8",
"express": "4.13.4"
},
"devDependencies": {
"webpack": "1.12.14"
}
}
15 changes: 5 additions & 10 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<link rel="stylesheet" href="/styles/main.css" type="text/css">
</head>
<body ng-app="todoListApp">

<h1>My TODOs!</h1>

<div class="list" ng-controller="mainCtrl">
<div class="add">
<a href="#" ng-click="addTodo()">
Expand All @@ -17,12 +17,7 @@ <h1>My TODOs!</h1>
<todo></todo>
</div>


<script src="/vendor/angular.js"></script>
<script src="/scripts/app.js"></script>
<script src="/scripts/controllers/main.js"></script>
<script src="/scripts/controllers/todo.js"></script>
<script src="/scripts/services/data.js"></script>
<script src="/scripts/directives/todo.js"></script>
<script src="/scripts/vendor.bundle.js"></script>
<script src="/scripts/todo.bundle.js"></script>
</body>
</html>
</html>
3 changes: 0 additions & 3 deletions public/scripts/app.js

This file was deleted.

17 changes: 17 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var webpack = require('webpack'),
path = require('path');

module.exports = {
context: __dirname + '/app',
entry: {
app: './app.js',
vendor: ['angular']
},
output: {
path: __dirname + '/public/scripts',
filename: 'todo.bundle.js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.bundle.js")
]
};

0 comments on commit d18e144

Please sign in to comment.