Skip to content

Commit 76b5917

Browse files
committed
增加模板后缀templateSuffix配置项
1 parent 94a9ad0 commit 76b5917

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
sandbox: {
2121
receiver: 'http://YOUR_HOST/receiver',
2222
templatePath: '/home/work/nginx_static/html/test/template',
23+
templateSuffix: '.html', // 模板后缀,不配置默认使用.tpl,也可传入'.(san|html)'
2324
staticPath: '//home/work/nginx_static/html/test/static',
2425
staticDomain: 'http://test.com:8888',
2526
throttle: 200 // 文件上传的延迟时间,默认为200ms

webpack-plugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const fsrUpload = require('./fsr');
1818
* sandbox: {
1919
* receiver: 'http://YOUR_HOST/receiver',
2020
* templatePath: '/home/work/nginx_static/html/test/template',
21+
* templateSuffix: '.tpl', // '.(san|html)'或 '\.(san|html)'
2122
* staticPath: '//home/work/nginx_static/html/test/static',
2223
* staticDomain: 'http://test.com:8888'
2324
* }
@@ -37,6 +38,9 @@ class Upload {
3738
};
3839
this.throttle = options.throttle || 200;
3940
this.compilationAssets = {};
41+
const tplSuffix = options.templateSuffix || '.tpl';
42+
// default: /\.tpl$/
43+
this.tplReg = new RegExp((tplSuffix.indexOf('.') === 0 ? '\\' : '') + tplSuffix + '$');
4044
}
4145

4246
apply(compiler) {
@@ -51,7 +55,7 @@ class Upload {
5155
// 过滤掉已经上传成功的文件
5256
const compilationAssets = this.filterFiles(compilation.assets);
5357
const targetFiles = Object.keys(compilationAssets).map(filename => {
54-
const to = /\.tpl$/.test(filename) ? options.templatePath : options.staticPath;
58+
const to = this.tplReg.test(filename) ? options.templatePath : options.staticPath;
5559
return {
5660
host: options.host,
5761
receiver: options.receiver,
@@ -94,7 +98,7 @@ class Upload {
9498
}
9599

96100
getContent(filename, compilation) {
97-
const isContainCdn = /\.(css|js|tpl)$/.test(filename);
101+
const isContainCdn = /\.(css|js)$/.test(filename) || this.tplReg.test(filename);;
98102
const source = compilation.assets[filename].source();
99103
if (isContainCdn) {
100104
const reg = new RegExp(this.options.baseUrl, 'g');

0 commit comments

Comments
 (0)