zoukankan      html  css  js  c++  java
  • [AngularJS + Webpack] Production Setup

    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;
  • 相关阅读:
    GMA Round 1 数列求单项
    GMA Round 1 双曲线与面积
    多线程环境中安全使用集合API(含代码)
    使用synchronized获取互斥锁的几点说明
    ThreadPoolExecutor线程池
    线程状态转换
    volatile关键字
    守护线程与线程阻塞的四种情况
    线程挂起,恢复与终止
    线程中断
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4796048.html
Copyright © 2011-2022 走看看