• [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;
  • 相关阅读:
    通过socket,实现简易版的通讯
    控制台报错[WDS] Disconnected!
    js里面可以提升性能的有哪些方法
    构造函数与普通函数的区别
    事件循环(event loop)
    二维数组的创建以及简单举例
    es5数组的api(了解)
    字符串的api (基础)
    git常用命令
    连接MongoDB失败,处理办法
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4796048.html
Copyright © 2020-2023  润新知