[AngularJS + Webpack] Using Webpack for angularjs

1. Install webpack & angular:

npm install webpack angular

 

2. Create webpack.config.js file:

module.exports = {
    context: __dirname + ‘/app‘,
    entry: ‘./app.js‘,
    output: {
        path: __dirname + ‘/build‘,
        filename: ‘bundle.js‘
    }
}

The context is: app folder

The entry file is: app.js

The output: path is build folder and filename is bundle.js.

技术分享

 

3. app.js:

var anuglar = require(‘angular‘);
var ngModule = angular.module(‘app‘, []);

console.log(ngModule);

 

4. index.js:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Webpack + AngularJS</title>
</head>
<body ng-app="app">

</body>
<script src="../build/bundle.js"></script>
</html>

 

5. run webpack:

webpack -watch

 

6. In the web broswer console, you will see the ngModule object.

技术分享

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。