[AngularJS + Webpack] Uglifying your JavaScript
Angular requires some careful consideration when uglifying your code because of how angular's dependency injection system works. See how easy it is to add this consideration to your webpack configuration so you can minify your Angular JavaScript with Webpack.
Install:
npm install --save-dev ng-annotate-loader
After babel compile the javascript code, we need to annotate the angular code:
{test: /\.js$/, loader: 'ng-annotate-loader!babel-loader', exclude: /node_modules/},
Uglify the Javascript in production env:
if(process.env.NODE_ENV === "production"){
config.output.path = __dirname + "/dist";
config.plugins.push(new webpack.optimize.UglifyJsPlugin()); // Uglify js
}
var webpack = require('webpack')
path = require('path'); path.resolve(__dirname, "app"); var config = {
context: __dirname + '/app',
entry: './index.js',
output: {
path: __dirname + '/app',
filename: 'bundle.js'
},
plugins: [
new webpack.DefinePlugin({
ON_TEST: process.env.NODE_ENV === "test"
})
],
module: {
loaders: [
{test: /\.js$/, loader: 'ng-annotate-loader!babel-loader', exclude: /node_modules/},
{test: /\.html$/, loader: 'html-loader', exclude: /node_modules/},
{test: /\.css$/, loader: 'style!css', exclude: /node_modules/},
{test: /\.styl/, loader: 'style!css!stylus', exclude: /node_modules/}
]
}
}; if(process.env.NODE_ENV === "production"){
config.output.path = __dirname + "/dist";
config.plugins.push(new webpack.optimize.UglifyJsPlugin()); // Uglify js
} module.exports = config;
If in the code, you need to tell the ng-annotate-loader to annotate the code just do:
controller: /*@ngInject*/ function(){
.....
}
[AngularJS + Webpack] Uglifying your JavaScript的更多相关文章
- [AngularJS + Webpack] require directives
direictives/index.js: module.exports = function(ngModule) { //register all the directives here requi ...
- [AngularJS + Webpack] Using Webpack for angularjs
1. Install webpack & angular: npm install webpack angular 2. Create webpack.config.js file: modu ...
- Webpack打包报"JavaScript heap out of memory"错误
问题 开发项目有一段时间了,随着项目越来越大,打包的时间也相应的变长了,打包时的内存也增多了.这时候产生了一个问题,在发布项目的时候,会出现JavaScript heap out of memory错 ...
- [BUGCASE]Webpack打包报JavaScript堆内存泄漏的错误
一.问题描述 执行npm run build之后报错: 报错信息: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript he ...
- [AngularJS + Webpack] Production Setup
Using Angular with webpack makes the production build a breeze. Simply alter your webpack configurat ...
- [AngularJS + Webpack] Requiring CSS & Preprocessors
Making your CSS modular is a difficult thing to do, but using Webpack makes this so much easier. By ...
- [AngularJS + Webpack] Requiring Templates
With Angular, most of the time you're specifying a templateUrl for your directives and states/routes ...
- [AngularJS + Webpack] ES6 with BabelJS
Install: npm install --save-dev babel-loader webpack.config.js: Add module, tell webpack to find all ...
- 虽然今天angular5发布了,但我还是吧这篇angularjs(1)+webpack的文章发出来吧哈哈哈
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/7779384.html 写在前面: 因为最近总结自己之前做过 ...
随机推荐
- ecshop 报错
ECShop出现Strict Standards: Only variables should be passed b (2014-06-04 17:00:37) 转载▼ 标签: ecshop 报错 ...
- javascript 与 java
- Spring4.0整合Hibernate3 .6
转载自:http://greatwqs.iteye.com/blog/1044271 6.5 Spring整合Hibernate 时至今日,可能极少有J2EE应用会直接以JDBC方式进行持久层访问. ...
- GNOME Shell叫板Ubuntu Unity:优劣PK
转自GNOME Shell叫板Ubuntu Unity:优劣PK GNOME Shell 对阵 Ubuntu Unity--默认桌面界面的战火一触即发.双方在台上已经对峙了很长时间,现在是时候决定谁会 ...
- log4j将日志输出到控制台,文件,邮件
#将日志写到文件 log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=e\:\ ...
- 我要爱死这个markdown 了
今天上班依旧看wpdang的文章,最后作者说,文章使用markdown写的,好奇心促使我搜了一把什么是markdown.然后看到了这篇文章,一瞬间就开始兴奋了.顿时觉得,这个东西太好用 了,简直又激起 ...
- Solr4.4的安装与配置
最近准备用Solr搭建项目,所以对其作了一些了解,我采用的是Solr4.4版本:这个版本的Solr相对于以前的版本改变很大,这里记一下自己安装与配置的过程. 网上很多关于Solr的教程都很老了,很多教 ...
- -_-#【HTML】同一个标签页打开
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- inuitcss
inuitcssa powerful, scalable, Sass-based, BEM, OOCSS framework.
- (转载)MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途
(转载)http://www.45it.com/database/201204/29390.htm 本文简要说明了MySQL数据库安装好后自带的INFORMATION_SCHEMA,MySQL,TES ...