From fcebc4ee1c42accfae070fdd51c5dc252d294833 Mon Sep 17 00:00:00 2001 From: zhangtingting12 Date: Tue, 10 Jan 2023 17:34:10 +0800 Subject: [PATCH 1/2] :sparkles: remote add templateSuffix config --- packages/san-cli-build/getWebpackConfig.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/san-cli-build/getWebpackConfig.js b/packages/san-cli-build/getWebpackConfig.js index 43b82568..52ec8662 100644 --- a/packages/san-cli-build/getWebpackConfig.js +++ b/packages/san-cli-build/getWebpackConfig.js @@ -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 @@ -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( From a6f6c93b00f35da9009064fed478987ca578894e Mon Sep 17 00:00:00 2001 From: zhangtingting12 Date: Tue, 10 Jan 2023 17:38:26 +0800 Subject: [PATCH 2/2] :white_check_mark: fix babel test and add doc --- docs/deployment.md | 14 +++++++++++--- docs/env.md | 1 + .../san-cli-plugin-babel/__tests__/preset.spec.js | 2 +- packages/san-cli/__tests__/e2e.spec.js | 2 +- packages/san-cli/__tests__/serveSan.spec.js | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/deployment.md b/docs/deployment.md index 7fcb7b49..1906547a 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -3,6 +3,8 @@ # 部署 在执行 `san build [entry] --remote ` 时,使用的就是该页面的远程部署解决方案,支持从项目本地将生产环境编译产出直接远程部署到目标开发机。 +如需在开发中代码每次更改自动部署至远端机器,实现代码更改实时push,可执行 `san build [entry] --watch --remote ` 命令 + 使用时,需要进行相应的 **环境配置** 以及 **参数配置**,下面具体说明如何配置。 ## 环境配置 @@ -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 @@ -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 。 ::: ### 远端机器 @@ -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` 远程服务的静态文件存放地址。 @@ -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): diff --git a/docs/env.md b/docs/env.md index aacbb466..ead51255 100644 --- a/docs/env.md +++ b/docs/env.md @@ -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 ``` diff --git a/packages/san-cli-plugin-babel/__tests__/preset.spec.js b/packages/san-cli-plugin-babel/__tests__/preset.spec.js index 9ccee6a5..64472e75 100644 --- a/packages/san-cli-plugin-babel/__tests__/preset.spec.js +++ b/packages/san-cli-plugin-babel/__tests__/preset.spec.js @@ -91,7 +91,7 @@ test('async/await', () => { await Promise.resolve(); } `, defaultOptions); - expect(code).toMatch('regenerator-runtime/runtime'); + expect(code).toMatch('regeneratorRuntime'); }); test('显式传入 polyfill', () => { diff --git a/packages/san-cli/__tests__/e2e.spec.js b/packages/san-cli/__tests__/e2e.spec.js index 4f931720..a4270ba7 100644 --- a/packages/san-cli/__tests__/e2e.spec.js +++ b/packages/san-cli/__tests__/e2e.spec.js @@ -1,5 +1,5 @@ // 运行测试的时间上限设为6分钟(默认是5秒,太短了不够用) -jest.setTimeout(360000); +jest.setTimeout(390000); const path = require('path'); const child_process = require('child_process'); diff --git a/packages/san-cli/__tests__/serveSan.spec.js b/packages/san-cli/__tests__/serveSan.spec.js index 4d9ff33d..ef8b36cf 100644 --- a/packages/san-cli/__tests__/serveSan.spec.js +++ b/packages/san-cli/__tests__/serveSan.spec.js @@ -1,4 +1,4 @@ -jest.setTimeout(30000); +jest.setTimeout(32000); const child_process = require('child_process'); const puppeteer = require('puppeteer');