6 Star 14 Fork 20

Choerodon/iam-service

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
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();
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/choerodon/iam-service.git
git@gitee.com:choerodon/iam-service.git
choerodon
iam-service
iam-service
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385