feat: add client devops and change local domain yapi.local.qunar.com

This commit is contained in:
suxiaoxin 2017-07-25 14:18:57 +08:00
parent a0aa06f46a
commit 3df7f38b42
14 changed files with 119 additions and 101 deletions

2
.gitignore vendored
View File

@ -36,5 +36,5 @@ Thumbs.db
node_modules/
runtime/init.lock
runtime/log
prd/
./prd/
dev/

View File

@ -16,6 +16,7 @@
"license": "ISC",
"dependencies": {
"@qnpm/ykit-config-qunar": "^0.8.2",
"assets-webpack-plugin": "^3.5.1",
"axios": "^0.16.2",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"core-decorators": "^0.17.0",
@ -43,6 +44,7 @@
"redux-thunk": "^2.2.0",
"request": "^2.81.0",
"sha1": "^1.1.1",
"string-replace-webpack-plugin": "^0.1.3",
"universal-cookie": "^2.0.8",
"wangeditor": "^3.0.4",
"ykit-config-antd": "^0.1.3",

View File

@ -1,6 +1,6 @@
{
"port": "3000",
"webhost": "127.0.0.1",
"webhost": "yapi.local.qunar.com",
"adminAccount": "admin@admin.com",
"db": {
"servername": "10.86.40.194",

36
static/dev.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>my yApi</title>
<link rel="stylesheet" href="http://127.0.0.1:4000/yapi/prd/index@dev.css">
<script src="https://qsso.corp.qunar.com/lib/qsso-auth.js"></script>
</head>
<body>
<div id="yapi" style="height: 100%;"></div>
<script src="http://127.0.0.1:4000/yapi/prd/index@dev.js"></script>
<!--
<button id="qsso-login">qsso登录</button>
<script src="https://qsso.corp.qunar.com/lib/qsso-auth.js"></script>
<script>
QSSO.attach('qsso-login','/user/login_by_token');
var xhr = new XMLHttpRequest();
xhr.open('GET', '/user/status')
xhr.onload = function(e){
if(this.status == 200){
alert(this.responseText)
}
}
xhr.send()
</script>
<html>
-->
</body>
</html>

View File

@ -4,33 +4,19 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>my yApi</title>
<link rel="stylesheet" href="http://127.0.0.1:4000/yapi/prd/index@dev.css">
<script>
document.write('<script src="prd/assets.js?v=' + Math.random() + '"><\/script>');
</script>
<script>
document.write('<link rel="stylesheet" href="/prd/' + window.WEBPACK_ASSETS['index.js'].css + '" />');
</script>
<script src="https://qsso.corp.qunar.com/lib/qsso-auth.js"></script>
</head>
<body>
<div id="yapi" style="height: 100%;"></div>
<script src="http://127.0.0.1:4000/yapi/prd/index@dev.js"></script>
<!--
<button id="qsso-login">qsso登录</button>
<script src="https://qsso.corp.qunar.com/lib/qsso-auth.js"></script>
<script>
QSSO.attach('qsso-login','/user/login_by_token');
var xhr = new XMLHttpRequest();
xhr.open('GET', '/user/status')
xhr.onload = function(e){
if(this.status == 200){
alert(this.responseText)
}
}
xhr.send()
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['index.js'].js + '"><\/script>');
</script>
<html>
-->
</body>
</html>

1
static/prd/assets.js Normal file
View File

@ -0,0 +1 @@
window.WEBPACK_ASSETS = {"index.js":{"js":"index.js","css":"index.css"}}

21
static/prd/index.css Normal file

File diff suppressed because one or more lines are too long

1
static/prd/index.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
4c1b3161122796d85b75b3c0f041cd26

View File

@ -1 +0,0 @@
064c5c9b316a6ad40669

View File

@ -1 +0,0 @@
064c5c9b316a6ad40669

View File

@ -1,3 +0,0 @@
index.css#064c5c9b316a6ad40669
index.js#064c5c9b316a6ad40669
chunk.json#4c1b3161122796d85b75b3c0f041cd26

View File

@ -1,61 +0,0 @@
const webpack = require('webpack')
const path = require('path')
const nodeExternals = require('webpack-node-externals')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
module.exports = {
// context: 如果不通过path.resolve 配置入口访问路径 watch: true失效
context: path.resolve('./client'),
entry: {
index: './index.js',
},
output: {
// filename: 编译的文件名 仅用于命名每个文件
// [name]: 多入口形式 入口文件名替换这里的name
// [chunkhash: num]: 入口文件的hash值 用于修改后清空缓存
// filename: '[name].[chunkhash:3].js',
filename: './[name].js',
// 包存放的目录
path: path.resolve('./build'),
},
devServer:{
contentBase:'./'
},
// target: 'node',
// externals: [nodeExternals()],
module: {
noParse: /\.css$/,
rules: [
{
test: /\.scss$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "sass-loader"
}
]
},
{
test: /\.(jsx|js)?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'react']
}
}
}
]
},
watch: true
}

58
ykit.js
View File

@ -1,31 +1,69 @@
var path = require('path');
var StringReplacePlugin = require("string-replace-webpack-plugin");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var AssetsPlugin = require('assets-webpack-plugin')
var assetsPluginInstance = new AssetsPlugin({
filename: 'static/prd/assets.js',
processOutput: function (assets) {
return 'window.WEBPACK_ASSETS = ' + JSON.stringify(assets);
}
})
module.exports = {
plugins: [{
name: 'qunar',
options: {
eslint: true,
configFile: path.resolve(__dirname, "./client/.eslintrc.js")
}
}, {
name: 'antd',
options: {
modifyQuery: function(defaultQuery) { // 可查看和编辑 defaultQuery
modifyQuery: function (defaultQuery) { // 可查看和编辑 defaultQuery
defaultQuery.plugins.push('transform-decorators-legacy');
return defaultQuery;
}
}
}],
// devtool: 'cheap-source-map',
config: {
config: function(ykit){
return {
exports: [
'./index.js'
],
modifyWebpackConfig: function(baseConfig) {
modifyWebpackConfig: function (baseConfig) {
baseConfig.devtool = 'cheap-module-eval-source-map'
baseConfig.context = path.resolve(__dirname, "client");
baseConfig.output.prd.path = 'static/prd';
baseConfig.output.prd.publicPath = '';
baseConfig.output.prd.filename = '[name][ext]'
var stringReplace = {
test: "/static/index.html$",
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /@@VERSION_NUM/,
replacement: function () {
return 11111
}
}
]
})
}
baseConfig.module.loaders.push(stringReplace)
baseConfig.plugins.push(new StringReplacePlugin())
baseConfig.plugins.push(assetsPluginInstance)
baseConfig.module.loaders.push({
test: /\.(sass|scss)$/,
loader: ykit.ExtractTextPlugin.extract(
require.resolve('css-loader')
+ '?sourceMap!'
+ require.resolve('fast-sass-loader') + '?sourceMap'
)
})
return baseConfig;
}
}
},
server: {
// true/false默认 false效果相当于 ykit server --hot