本文Demo的完整工程代码, 参考dva-incremental-updating
目录
start
dva new dva-incremental-updating-html
npm run build && cat dist/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dva Demo</title>
<link rel="stylesheet" href="/index.css" />
<link href="/index.css" rel="stylesheet"></head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/index.js"></script></body>
</html>
template
vim src/index.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<link rel="shortcut icon" href="//a.zhgcloud.com/static/favicon.ico" />
<title>机械指挥官 - 工程机械物联网智慧管理解决方案</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
npm run build && cat dist/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<link rel="shortcut icon" href="//a.zhgcloud.com/static/favicon.ico" />
<title>机械指挥官 - 工程机械物联网智慧管理解决方案</title>
<link href="/index.css" rel="stylesheet"></head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/index.js"></script></body>
</html>
hash
vim .roadhogrc
{
"entry": "src/index.js",
"env": {
"development": {
"extraBabelPlugins": [
"dva-hmr",
"transform-runtime"
]
},
"production": {
"extraBabelPlugins": [
"transform-runtime"
]
}
},
"hash": true
}
npm run build && cat dist/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<link rel="shortcut icon" href="//a.zhgcloud.com/static/favicon.ico" />
<title>机械指挥官 - 工程机械物联网智慧管理解决方案</title>
<link href="/index.b8406158.css" rel="stylesheet"></head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/index.8e912c9d.js"></script></body>
</html>
gulp
cnpm i -g gulp && cnpm i --save-dev gulp gulp-shell
vim gulpfile.js
var gulp = require('gulp');
var shell = require('gulp-shell');
var buildType = 'production';
gulp.task('build', shell.task([
'npm run build',
'echo production server deploy success!'
]));
gulp.task('deploy-production', ['build'], shell.task([
'echo production server deploy success!'
]));
gulp.task('default', [`deploy-${buildType}`]);
gulp
url
vim change_url.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def chnage_url():
file = open('./dist/index.html', 'r+')
lines = file.readlines()
file.seek(0)
for line in lines:
new_line = line.replace('/index', '//a.zhgcloud.com/index')
file.write(new_line)
file.close()
chnage_url()
vim gulpfile.js
gulp.task('deploy-production', ['build'], shell.task([
'./change_url.py',
'echo production server deploy success!'
]));
参考
更多文章, 请支持我的个人博客