MSBuild and Webpack

前端 未结 2 1703
遥遥无期
遥遥无期 2020-12-24 09:19

I am developing an Angular2 application in VS2015 and have a webpack bundling and minification environment set up for the same.

This is my webpack.conf.js

2条回答
  •  心在旅途
    2020-12-24 09:35

    Put different scripts in package.json for development and production mode. Then on 'AfterBuild' event of visual studio, call those scripts on different configurations.

    Add following two scripts, 'buildDev' and 'buildProd' in package.json:

    "scripts": {
        "buildDev": "SET NODE_ENV=development && webpack -d --color",
        "buildProd": "SET NODE_ENV=production && webpack -p --color",
      }
    

    In AfterBuild events of visual studio add these two conditional commands:

    
        
        
      
    

    And finally webpack.conf.js like this:

    switch (process.env.NODE_ENV.trim()) {
        case 'prod':
        case 'production':
            module.exports = require('./config/webpack.prod');
            break;
        case 'dev':
        case 'development':
        default:
            module.exports = require('./config/webpack.dev');
            break;
    }
    

    Important Note: Make sure to use trim() function with process.env.NODE_ENV as cmd will treat the blank space in the command "SET NODE_ENV=development && webpack -d --color as character and append it in NODE_ENV variable. So when we are setting it as 'development', it actually gets set as (development + whitespace).

提交回复
热议问题