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. 入门6:PHP 语法基础——循环

    一.for循环 for($i=0;$i<10;$i++){ echo "Hello".$i."</br>"; } 二.while循环 $i = ...

  2. [Linux]Ubuntu下如何将普通用户提升到root权限

    转至:http://jingyan.baidu.com/album/6181c3e0780131152ef153ff.html?picindex=0&qq-pf-to=pcqq.c2c  在u ...

  3. ubuntu chm文档阅读

    四种方法在Ubuntu下查看CHM文件 来源:http://os.51cto.com/art/201108/287748.htm Ubuntu是一个以桌面应用为主的Linux操作系统,刚开始使用Ubu ...

  4. 开启g++ 编辑器 c++11特性

    以前都是在windows下用vs和cvi写C和C++代码,最近练习Linux下的使用. 编译的时候使用C++11的新特性比如auto 和 iteration特性都报不支持,后来在知乎看到答案需要在编译 ...

  5. 关于一个简单面试题(。net)

    猫大叫一声,主人被惊醒,所有的小老鼠开始逃窜. 期初想到的是事件调用方法. 在猫叫的事件中调用一对方法就可以了. 但是,当事件很多的时候 难保大家写着写着就忘记了. 总不能有 10000个人的时候调用 ...

  6. Servlet 是否线程安全 看完便知

    Servlet 是否线程安全 看完便知 转自:http://blog.sina.com.cn/s/blog_6448959f0100kct7.html     摘 要:介绍了Servlet多线程机制, ...

  7. PAT (Basic Level) 1013. 数素数 (20)

    令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有素数. 输入格式: 输入在一行中给出M和N,其间以空格分隔. 输出格式: 输出从PM到PN的所有素数 ...

  8. 安卓天天练练(三)常用组件Toast

    要写几句java package com.narumi.android_7_2; import android.app.Activity; import android.os.Bundle; impo ...

  9. 你真的了解 MySQL 数据库的运行状况吗?

    2015年第三方市场调查机构 Evans 数据公司最近公布的一系列客户调查数据显示,在过去两年里,MySQL 在所有开发者使用的数据库中获得了25%的市场份额,Evans 公司的本次调查显示,数据库的 ...

  10. 安装drupal练习网站遇到的问题

    1 Skip #conjunction key in __clone() method of core/includes/database/query.inc 解决方案:https://www.dru ...