webpack配置接口路径

好比在webpack.config.js中的plugins中加入html

new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('production'),
        IS_SIGN: JSON.stringify('prodsign')
 }),

而后就能够根据IS_SIGN来判断了webpack

/* global IS_SIGN:true */
console.log(IS_SIGN);
switch (IS_SIGN) {
    case 'localsign':
        API = 'http://192.168.1.xx:9090/';
        WEB = 'http://192.168.1.xx:8080/';
        break;
    case 'testsign':
        API = 'http://192.168.1.xx:9090/';
        WEB = 'http://heiyanquan.github.com/test.html';
        break;
    case 'prodsign':
        API = 'http://192.168.1.xx:9090/';
        WEB = 'http://heiyanquan.github.com/index.html';
        break;
}

须要注意的是,若是你在webpack里整合了ESLint,那么,因为ESLint会检测没有定义的变量(ESLint要求使用全局变量时要用window.xxxxx的写法),所以须要一个global注释声明(/ global IS_PRODUCTION:true /)IS_SIGN是一个全局变量来规避warning。git

相关文章
相关标签/搜索