代码拉取完成,页面将自动刷新
const path = require('path');
const gulp = require('gulp');
const rimraf = require('rimraf');
const babel = require('gulp-babel');
const through2 = require('through2');
const cwd = process.cwd();
const libDir = path.join(cwd, 'lib');
function compileAssets() {
return gulp.src(['react/**/*.@(jpg|png|svg|scss|less|html|ico)']).pipe(gulp.dest(libDir));
}
function getBabelCommonConfig() {
const plugins = [
require.resolve('babel-plugin-syntax-dynamic-import'),
require.resolve('babel-plugin-transform-decorators-legacy'),
require.resolve('babel-plugin-transform-es3-member-expression-literals'),
require.resolve('babel-plugin-transform-es3-property-literals'),
require.resolve('babel-plugin-transform-object-assign'),
require.resolve('babel-plugin-transform-class-properties'),
require.resolve('babel-plugin-transform-object-rest-spread'),
[require.resolve('babel-plugin-transform-runtime'), {
polyfill: false,
}],
[
require.resolve('babel-plugin-import'),
[
{
libraryName: 'choerodon-ui',
style: true,
},
{
libraryName: 'choerodon-ui/pro',
style: true,
},
],
],
require.resolve('babel-plugin-lodash'),
];
return {
presets: [
require.resolve('babel-preset-react'),
require.resolve('babel-preset-es2015'),
require.resolve('babel-preset-stage-1'),
],
plugins,
};
}
function babelify(js, dir = '') {
const babelConfig = getBabelCommonConfig();
const stream = js.pipe(babel(babelConfig));
return stream
// eslint-disable-next-line func-names
.pipe(through2.obj(function (file, encoding, next) {
const matches = file.path.match(/(routes|dashboard|guide|entry|entrywithoutsider)\.nunjucks\.(js|jsx)/);
if (matches) {
const content = file.contents.toString(encoding);
file.contents = Buffer.from(content
.replace(`'{{ ${matches[1]} }}'`, `{{ ${matches[1]} }}`)
// eslint-disable-next-line quotes
.replace(`'{{ home }}'`, '{{ home }}')
// eslint-disable-next-line quotes
.replace(`'{{ master }}'`, '{{ master }}'));
}
this.push(file);
next();
}))
.pipe(gulp.dest(path.join(libDir, dir)));
}
function compileFile() {
const source = [
'react/**/*.js',
'react/**/*.jsx',
];
return babelify(gulp.src(source));
}
function compile() {
rimraf.sync(libDir);
compileAssets();
compileFile();
}
gulp.task('compile', () => {
compile();
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。