代码拉取完成,页面将自动刷新
const gulp = require('gulp');
const shell = require('gulp-shell');
const spaceid = require('./package.json').spaceid;
gulp.task('watch-ts', shell.task('tsc -w -m umd'));
gulp.task('build-html', () => {
const through = require('through2');
const rename = require('gulp-rename');
const path = require('path');
const minifyHtml = require("gulp-minify-html");
return gulp.src('./src-web/**/html.ts')
.pipe(rename((file) => {
const page_no = file.dirname;
file.basename = page_no;
file.extname = '.html';
file.dirname = '../pages';
}))
.pipe(through.obj((chunk, enc, callback) => {
const page_no = path.basename(chunk.path, '.html');
const head = Buffer.from(`<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<link rel="stylesheet" type="text/css" href="../css/iconfont-web.css">
<link href="https://cdn.jsdelivr.net/npm/feidao-css/feidao.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="../css/daokes-web.css">
<script src="../../node_modules/@dojo/loader/loader.js"></script>
<script type="text/javascript">
(function(){
require.config({
baseUrl: '../../node_modules/',
packages: [{
name: 'daoke',
location: '../dist/src-web'
},{
name: '@feidao/core',
location: '@feidao/core/umd'
},{
name: '@feidao/web',
location: '@feidao/web/umd'
},{
name: '@feidao/web/atom/nodejs/msg',
location: '@feidao/web/umd/atom/nodejs/msg-b'
},{
name: '@feidao/web/atom/nodejs/authorization',
location: '@feidao/web/umd/atom/nodejs/authorization-b'
},{
name: '@feidao/widgets',
location: '@feidao/widgets/umd'
},{
name: '@feidao/widgets/fd-w000007',
location: '@feidao/widgets/umd',
main: 'fd-w000007-d'
},{
name: '@feidao/animation',
location: '@feidao/animation/umd',
main: 'index'
},{
name: 'node-html-parser',
location: 'node-html-parser/dist/umd',
main: 'index'
},{
name: 'javascript-state-machine',
location: './javascript-state-machine',
main: 'state-machine'
},{
name: 'dask',
location: 'dask/umd',
main: 'index'
},{
name: 'mqtt',
location: './mqtt/dist',
main: 'mqtt'
},{
name: 'dot',
location: 'dot',
main: 'doT'
},{
name: 'nools-ts',
location: 'nools-ts/umd'
},{
name: 'lodash-ts',
location: 'lodash-ts/umd'
},{
name: 'he',
location: './he',
main: 'he.js'
},{
name: 'quill',
location: './quill/dist',
main: 'quill.min'
},{
name: '@feidao/bscroll',
location: './@feidao/bscroll/dist',
main: "bscroll.js"
},{
name: 'jstree',
location: './jstree/dist',
main: 'jstree'
},{
name: 'jquery',
location: './jquery/dist',
main: 'jquery'
}, {
name: '@feidao/datepicker.js',
location: './@feidao/datepicker.js',
main: 'datepicker'
}, {
name: 'bootstrap-multiselect',
location: './bootstrap-multiselect',
main: 'dist/js/bootstrap-multiselect'
},{
name: 'uppy',
location: './uppy/dist',
main: 'uppy'
}, {
name: 'echarts',
location: './echarts/dist',
main: "echarts"
}, {
name: 'echarts/theme',
location: './echarts/theme/'
}, {
name: 'three',
location: './three/build/',
main: "three.js"
}, {
name: 'qiniu-js',
location: './qiniu-js/dist/',
main: "qiniu.min.js"
}, {
name: '@taoqf/slim-select',
location: '../node_modules/@taoqf/slim-select/dist',
main: 'slimselect'
}, {
name: 'select2',
location: '../node_modules/select2/dist/js',
main: 'select2.js'
}]
});
})();
</script>
</head>
<body>`, 'utf8');
const tail = Buffer.from(`
<script type="text/javascript">
(function(){
window.url = \`http://\${window.location.hostname}:8889/sendmessage\`;
require(['daoke/${page_no}/n'],function(main){
var url = window.location.href;
main.default(url, {cookie:{}}, {
spaceid: '${spaceid}',
sessionid: 'test',
actionid: 'test'
}).then(function(res){
// 去掉n返回页面的头部内容,只留body内容
const data = res.data;
const content = data.match(/<body[\\s|\\S]+>([\\s|\\S]+)<\\/body>/);
document.body.innerHTML = content[0];
require(['daoke/${page_no}/b']);
});
});
})();
</script>
</body></html>`, 'utf8');
// const body = chunk.contents.toString('utf8');
chunk.contents = Buffer.concat([head, /*Buffer.from(body.substring(body.indexOf('`') + 1, body.lastIndexOf('`'))), */tail]);
// this.push(chunk);
// callback();
callback(null, chunk);
}))
.pipe(minifyHtml()) //压缩
.pipe(gulp.dest('./dist/pages/'));
});
gulp.task('webpack', (cb) => {
const dest = './dist/js/';
const pack_file_path = `./dist/!(zj-)*/*/b.js`;
const path = require('path');
const webpack = require('webpack');
const through = require('through');
const ws = require('webpack-stream');
return gulp.src([pack_file_path])
.pipe(((opts) => {
return through(function (file) {
file.named = path.basename(path.dirname(file.path));
this.queue(file);
});
})())
.pipe(ws({
mode: 'production',
// mode: 'development',
optimization: {
splitChunks: {
name: 'feidao',
chunks: 'all'
}
},
externals: [
// "nools" // this is a bad js file
],
output: {
filename: '[name].js',
globalObject: 'window',
publicPath: dest
},
module: {
rules: [{
test: /\.js$/,
// exclude: /(node_modules|bower_components)/,
exclude: /core-js|babel|tus-js-client/,
use: {
loader: 'babel-loader'
}
}]
}
}, webpack))
.on('error', (e) => {
cb(e);
})
.pipe(gulp.dest(dest));
});
gulp.task('browser-sync', () => {
const browserSync = require('browser-sync').create();
browserSync.init({
files: ['./dist/'],
server: {
baseDir: './dist/pages',
directory: true
},
online: true,
host: '127.0.0.1',
open: 'external',
serveStatic: ['./'],
port: 8000
});
});
gulp.task('dev', shell.task(`feidao-dev -s ${process.cwd()}/service/dist/`));
gulp.task('service-watch', shell.task(`tsc -w -p ./service/tsconfig.json`));
gulp.task('daoke', gulp.parallel('watch-ts', 'build-html', 'browser-sync', 'dev', 'service-watch'));
gulp.task('default', gulp.parallel('webpack'));
gulp.task('config', async (cb) => {
const fs = require('fs').promises;
const through = require('through2');
return gulp.src(['./src-web/**/zj**'])
.pipe(through.obj(function (file, encode, callback) {
const p = file.path;
const id = p.substr(p.lastIndexOf('/') + 1);
fs.writeFile(file.path + '/config.ts', `export * from '../../atom-web/config';\nexport const id = '${id}';\n`);
callback();
}));
});
gulp.task('compress-service', () => {
const uglify = require('gulp-uglify-es').default;
return gulp.src(['dist/src-web/**/*.js', 'dist/src-h5/**/*.js', 'dist/!(src-*-app)*/**/*.js'])
.pipe(uglify({
compress: {
drop_console: true,
ecma: 8
}
}))
.pipe(gulp.dest(`release-service/projects/${spaceid}/`));
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。