Commit 0b084b2c by 万亚飞

fix bug

parent 14fcc746
//开发环境
module.exports = {
NODE_ENV: '"development"',
prefix: '"https://testapi.ydl.com/api"',
prefixH2: '"https//testh2.yidianling.com"'
};
module.exports = {
NODE_ENV: '"production"',
prefix: '"https://api.ydl.com/api"',
prefixH2: '"https://h2.yidianling.com"'
};
module.exports = {
NODE_ENV: '"testing"',
prefix: '"https://testapi.ydl.com/api"',
prefixH2: '"https//testh2.yidianling.com"'
};
...@@ -3,6 +3,7 @@ const path = require('path'); ...@@ -3,6 +3,7 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack'); const webpack = require('webpack');
const os = require('os'); const os = require('os');
const env = require(`./dev.env`);
function resolveRoot(dir) { function resolveRoot(dir) {
return path.join(__dirname, '..', dir); return path.join(__dirname, '..', dir);
} }
...@@ -100,6 +101,9 @@ module.exports = { ...@@ -100,6 +101,9 @@ module.exports = {
] ]
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({
'process.env': env
}),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './public/index.html' template: './public/index.html'
}), }),
......
...@@ -8,6 +8,9 @@ const CleanWebpackPlugin = require('clean-webpack-plugin'); ...@@ -8,6 +8,9 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin'); const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin');
const PrerenderSPAPlugin = require('prerender-spa-plugin'); const PrerenderSPAPlugin = require('prerender-spa-plugin');
const PreloadWebpackPlugin = require('preload-webpack-plugin'); const PreloadWebpackPlugin = require('preload-webpack-plugin');
const env = require(`./${process.env.NODE_ENV}.env`);
console.log('env', process.env.NODE_ENV, env);
const os = require('os'); const os = require('os');
function resolveRoot(dir) { function resolveRoot(dir) {
return path.join(__dirname, '..', dir); return path.join(__dirname, '..', dir);
......
...@@ -72,10 +72,26 @@ ...@@ -72,10 +72,26 @@
"scripts": { "scripts": {
"start": "webpack-dev-server --config ./config/webpack.dev.js", "start": "webpack-dev-server --config ./config/webpack.dev.js",
"dev": "webpack-dev-server --config ./config/webpack.dev.js", "dev": "webpack-dev-server --config ./config/webpack.dev.js",
"build": "webpack --config ./config/webpack.prod.js " "build:test": "better-npm-run build:test",
"build:prod": "better-npm-run build:test"
},
"betterScripts": {
"build:test": {
"command": "webpack --config ./config/webpack.prod.js",
"env": {
"NODE_ENV": "testing"
}
},
"build:prod": {
"command": "webpack --config ./config/webpack.prod.js",
"env": {
"NODE_ENV": "production"
}
}
}, },
"devDependencies": { "devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-syntax-dynamic-import": "^7.2.0",
"better-npm-run": "^0.1.1",
"preload-webpack-plugin": "^3.0.0-beta.3" "preload-webpack-plugin": "^3.0.0-beta.3"
}, },
"theme": { "theme": {
......
...@@ -92,17 +92,13 @@ function toFormData(data) { ...@@ -92,17 +92,13 @@ function toFormData(data) {
/** /**
*获取http请求路径 *获取http请求路径
* @param { api中的键值 } key * @param { api中的键值 } key
* @param { 是否走网关 } gateWay
*/ */
export function getApi(key, option) { export function getApi(key, option) {
// const ENV = process.env; const { prefix, prefixH2 } = process.env;
let prx = option.isPrefixH2 ? baseHostH2 : baseHostUrlApi; let prx = option.isPrefixH2 ? prefixH2 : prefix;
// option.mock && (prx = ENV.mock);
let _api = Api[key]; let _api = Api[key];
if (!/\/$/.test(prx) && !/^\//.test(_api)) { if (!/\/$/.test(prx) && !/^\//.test(_api)) {
_api = '/' + _api; _api = '/' + _api;
} }
return prx + _api; return prx + _api;
} }
// export let get = (url, options = {}) => ajax(url, 'get', options);
// export let post = (url, options = {}) => ajax(url, 'post', options);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment