Using Angular with webpack makes the production build a breeze. Simply alter your webpack configuration at runtime based on an environment variable, and you're good to go.

package.json:

  "scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --content-base app",
"build": "set NODE_ENV=production && cp app/index.html build/index.html && webpack"
},

In Windows, when you want to set Node env, you should do :

set NODE_ENV=production

//in Mac
NODE_ENV=production

Copy the index.html to the build dir:

cp app/index.html build/index.html 

Then run webpack, if u have installed the webpack globally, then just write:

webpack

webpack.config.js>

var webpack = require('webpack');

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: '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 + "/build"
} module.exports = config;

[AngularJS + Webpack] Production Setup的更多相关文章

  1. [Webpack 2] Optimize React size and performance with Webpack production plugins

    You can fine tune several webpack plugins to make your bundle as small as it can be for your specifi ...

  2. [AngularJS + Webpack] require directives

    direictives/index.js: module.exports = function(ngModule) { //register all the directives here requi ...

  3. [AngularJS + Webpack] Using Webpack for angularjs

    1. Install webpack & angular: npm install webpack angular 2. Create webpack.config.js file: modu ...

  4. [AngualrJS + Webpack] Production Source Maps

    When you uglify your Angular code with Webpack's uglify plugin, debugging your application can be a ...

  5. [AngularJS + Webpack] Uglifying your JavaScript

    Angular requires some careful consideration when uglifying your code because of how angular's depend ...

  6. [AngularJS + Webpack] Requiring Templates

    With Angular, most of the time you're specifying a templateUrl for your directives and states/routes ...

  7. [AngularJS + Webpack] Requiring CSS & Preprocessors

    Making your CSS modular is a difficult thing to do, but using Webpack makes this so much easier. By ...

  8. [AngularJS + Webpack] ES6 with BabelJS

    Install: npm install --save-dev babel-loader webpack.config.js: Add module, tell webpack to find all ...

  9. 虽然今天angular5发布了,但我还是吧这篇angularjs(1)+webpack的文章发出来吧哈哈哈

    本文为原创,转载请注明出处: cnzt       文章:cnzt-p http://www.cnblogs.com/zt-blog/p/7779384.html 写在前面: 因为最近总结自己之前做过 ...

随机推荐

  1. sublime text下载和汉化

    好处就不说了,能认识到这款编辑器,基本上对它有一定的了解了. Sublime Text2是一款开源的软件,不需要注册即可使用(虽然没有注册会有弹窗,但是基本不影响使用). 官方网站:http://ww ...

  2. 精通 Oracle+Python,第 9 部分:Jython 和 IronPython — 在 Python 中使用 JDBC 和 ODP.NET

    成功的编程语言总是会成为顶级开发平台.对于 Python 和世界上的两个顶级编程环境 Java 和 Microsoft .NET 来说的确如此. 虽然人们因为 Python 能够快速组装不同的软件组件 ...

  3. #Leet Code# Same Tree

    语言:Python 描述:使用递归实现 # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # ...

  4. Administration Commands

    Commands useful for administrators of a hadoop cluster. balancer Runs a cluster balancing utility. A ...

  5. MAC 安装Ruby On Rails

    MAC 安装Ruby On Rails 对于新入门的开发者,如何安装 Ruby, Ruby Gems 和 Rails 的运行环境可能会是个问题,本页主要介绍如何用一条靠谱的路子快速安装 Ruby 开发 ...

  6. PHP之路——Redis安装

    windows: redis下载链接:https://github.com/ServiceStack/redis-windows 然后编辑redis.windows.conf文件,我看网上有的教程说编 ...

  7. iOS NSDecimalNumber 货币计算 四舍五入

    今天遇到一个问题 服务器返回货币数据 妈的 用string > floatvalue   不准确 去百度查查 妈的国人分享精神真差  真他妈的自私 一个破壁文章没几个字 还是从国外翻译过来的 全 ...

  8. android学习小例子——验证码倒计时按钮

    1.activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andro ...

  9. Windows Azure 配置SSTP

    方法參考下面文章的步驟. 这个成功.http://freevpnba.com/windows-azure-sstp-vpn/ 这个没成功,不知道为什么.http://diaosbook.com/pos ...

  10. C语言中结构体对齐问题

    C语言中结构体对齐问题 收藏 关于C语言中的结构体对齐问题 1,比如: struct{short a1;short a2;short a3;}A;struct{long a1;short a2;}B; ...