Skip to content

Commit

Permalink
Merge pull request #339 from zttonly/master
Browse files Browse the repository at this point in the history
remote增加模板后缀配置
  • Loading branch information
jinzhan authored Jan 11, 2023
2 parents 3926b4c + a6f6c93 commit b83ece6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
14 changes: 11 additions & 3 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# 部署
在执行 `san build [entry] --remote <remote-name>` 时,使用的就是该页面的远程部署解决方案,支持从项目本地将生产环境编译产出直接远程部署到目标开发机。

如需在开发中代码每次更改自动部署至远端机器,实现代码更改实时push,可执行 `san build [entry] --watch --remote <remote-name>` 命令

使用时,需要进行相应的 **环境配置** 以及 **参数配置**,下面具体说明如何配置。

## 环境配置
Expand All @@ -15,6 +17,7 @@
SAN_REMOTE_XIAOMING_DISABLE_FSR=true
SAN_REMOTE_XIAOMING_RECEIVER=http://www.xiaoming.com:8080/receiver.php
SAN_REMOTE_XIAOMING_TEMPLATE_PATH=/home/work/nginx_static/html/test/template
SAN_REMOTE_XIAOMING_TEMPLATE_SUFFIX=.html
SAN_REMOTE_XIAOMING_STATIC_PATH=/home/work/nginx_static/html/test/static
SAN_REMOTE_XIAOMING_STATIC_DOMAIN=http://test.bdstatic.com:8888
SAN_REMOTE_XIAOMING_BASE_URL=http://www.cdnstatic.com
Expand All @@ -24,7 +27,7 @@ SAN_REMOTE_XIAOMING_HOST=http://www.xiaoming.com:8080

::: warning 上例解读
1. 命名规则:**SAN_REMOTE_(1.大写的 remote-name 名称)_ (2.大写的参数名称,驼峰处改用下划线分隔)**;其中【1】的与remote-name相同,【2】会解析为配置参数,具体含义见**参数配置**
2. 将 tpl、js、css 文件代码中 http://www.cdnstatic.com 替换成了 http://test.bdstatic.com:8888
2. 将模板(默认tpl)、js、css 文件代码中 http://www.cdnstatic.com 替换成了 http://test.bdstatic.com:8888
:::

### 远端机器
Expand All @@ -43,7 +46,12 @@ SAN_REMOTE_XIAOMING_HOST=http://www.xiaoming.com:8080
远程服务的 receiver.php 地址,receiver.php 文件内容[参考](https://github.com/fex-team/fis3-deploy-http-push/blob/master/receiver.php)

#### `templatePath`
远程服务的模板存放地址,产出文件中的 .tpl 结尾的文件会上传到此路径下。
远程服务的模板存放地址,产出文件中的 .tpl (默认后缀, 可通过templateSuffix修改) 结尾的文件会上传到此路径下。

#### `templateSuffix`
项目中模板文件后缀,如:'.html',不配置时默认 '.tpl'

>> san-cli-build > 2.1.1 & deploy-files > 0.2.3 支持
#### `staticPath`
远程服务的静态文件存放地址。
Expand Down Expand Up @@ -76,7 +84,7 @@ san build --remote xiaoming --watch

## 简单说实现

使用[deploy-files](https://github.com/jinzhan/deploy-files)插件。
使用[deploy-files](https://github.com/wanwu/deploy-files)插件。

安装 deploy-files (版本 >= 0.1.1):

Expand Down
1 change: 1 addition & 0 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SAN_VAR_TRUE=true
# .env.production
SAN_REMOTE_XIAOMING_RECEIVER=http://www.xiaoming.com:8080/receiver.php
SAN_REMOTE_XIAOMING_TEMPLATE_PATH=/home/work/nginx_static/html/test/template
SAN_REMOTE_XIAOMING_TEMPLATE_SUFFIX=.html # 可选
SAN_REMOTE_XIAOMING_STATIC_PATH=/home/work/nginx_static/html/test/static
SAN_REMOTE_XIAOMING_STATIC_DOMAIN=http://test.bdstatic.com:8888
```
Expand Down
7 changes: 4 additions & 3 deletions packages/san-cli-build/getWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ module.exports = function getNormalizeWebpackConfig(api, projectConfigs, argv) {
if (remote) {
const DeployPlugin = require('deploy-files/webpack-plugin');
// 从 env 文件中读取 remote 配置,这样可以将 env.local 加到 .gitignore 中防止提交
// 详细配置:https://github.com/jinzhan/deploy-files
// 详细配置:https://github.com/wanwu/deploy-files
// host: 'http://YOUR_HOST'
// receiver: 'http://YOUR_HOST/receiver',
// templatePath: '/home/work/nginx_static/html/test/template',
// templateSuffix: '.html',
// staticPath: '//home/work/nginx_static/html/test/static',
// staticDomain: 'http://test.com:8888'
// baseUrl: 'https://s.bdstatic.com/'
const upperRemote = remote.toUpperCase();
const requiredParam = ['templatePath', 'staticPath', 'staticDomain', 'baseUrl'];
const requiredParam = ['templatePath', 'staticPath', 'staticDomain', 'baseUrl', 'templateSuffix'];
const remoteObj = {
// 1. 默认取false;
// 2. process.env读取的内容为string,需转boolean
Expand All @@ -83,7 +84,7 @@ module.exports = function getNormalizeWebpackConfig(api, projectConfigs, argv) {
// templatePath → TEMPLATE_PATH
const upperKey = key.replace(/[A-Z]/g, $1 => `_${$1}`).toUpperCase();
const val = process.env[`SAN_REMOTE_${upperRemote}_${upperKey}`];
if (!val) {
if (key !== 'templateSuffix' && !val) {
error(
/* eslint-disable max-len */
`Use --remote ${remote} to upload files, but donot get ${chalk.red(
Expand Down
2 changes: 1 addition & 1 deletion packages/san-cli-plugin-babel/__tests__/preset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test('async/await', () => {
await Promise.resolve();
}
`, defaultOptions);
expect(code).toMatch('regenerator-runtime/runtime');
expect(code).toMatch('regeneratorRuntime');
});

test('显式传入 polyfill', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/san-cli/__tests__/e2e.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 运行测试的时间上限设为6分钟(默认是5秒,太短了不够用)
jest.setTimeout(360000);
jest.setTimeout(390000);

const path = require('path');
const child_process = require('child_process');
Expand Down
2 changes: 1 addition & 1 deletion packages/san-cli/__tests__/serveSan.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000);
jest.setTimeout(32000);

const child_process = require('child_process');
const puppeteer = require('puppeteer');
Expand Down

0 comments on commit b83ece6

Please sign in to comment.