Skip to content

Commit

Permalink
add es
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed May 2, 2017
1 parent 8626d52 commit 2c37699
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 423 deletions.
28 changes: 18 additions & 10 deletions lib/getBabelCommonConfig.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const plugins = [require.resolve('babel-plugin-add-module-exports')];

if (argv['babel-runtime']) {
plugins.push([require.resolve('babel-plugin-transform-runtime'), {
polyfill: false,
}]);
}

module.exports = function () {
module.exports = function (modules) {
const plugins = [
require.resolve('babel-plugin-transform-es3-member-expression-literals'),
require.resolve('babel-plugin-transform-es3-property-literals'),
];
if (modules !== false) {
plugins.push(require.resolve('babel-plugin-add-module-exports'));
}
if (argv['babel-runtime']) {
plugins.push([require.resolve('babel-plugin-transform-runtime'), {
polyfill: false,
}]);
}
return {
presets: ['es2015-ie', 'react', 'stage-0'].map((name) => {
return require.resolve(`babel-preset-${name}`);
}),
presets: [[require.resolve(`babel-preset-es2015`), {
modules,
}]].concat(['react', 'stage-0'].map((name) => {
return require(`babel-preset-${name}`);
})),
plugins,
};
};
14 changes: 0 additions & 14 deletions lib/gulpEs3ify.js

This file was deleted.

35 changes: 22 additions & 13 deletions lib/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ const runCmd = require('./util').runCmd;
const fs = require('fs-extra');
const lessPath = new RegExp(`(["\']${pkg.name})\/assets\/([^.\'"]+).less`, 'g');
const argv = require('minimist')(process.argv.slice(2));
const babelConfig = require('./getBabelCommonConfig')();
const getBabelCommonConfig = require('./getBabelCommonConfig');
const postcss = require('gulp-postcss');
const gulpEs3ify = require('./gulpEs3ify');
const getNpm = require('./getNpm');
const selfPackage = require('../package.json');
const chalk = require('chalk');
Expand Down Expand Up @@ -85,6 +84,9 @@ function cleanCompile() {
if (fs.existsSync(resolveCwd('lib'))) {
shelljs.rm('-rf', resolveCwd('lib'));
}
if (fs.existsSync(resolveCwd('es'))) {
shelljs.rm('-rf', resolveCwd('es'));
}
if (fs.existsSync(resolveCwd('assets'))) {
shelljs.rm('-rf', resolveCwd('assets/*.css'));
}
Expand Down Expand Up @@ -252,14 +254,13 @@ gulp.task('pub', ['publish', 'gh-pages'], () => {
console.log('tagged');
});

function babelify(js) {
function babelifyInternal(js, modules) {
function replacer(match, m1, m2) {
return `${m1}/assets/${m2}.css`;
}

return js.pipe(babel(babelConfig))
.pipe(gulpEs3ify())
.pipe(gulp.dest('lib'))
return js.pipe(babel(getBabelCommonConfig(modules)))
.pipe(gulp.dest(modules !== false ? 'lib' : 'es'))
.pipe(through2.obj(function (file, encoding, next) {
file.contents = new Buffer(file.contents.toString(encoding)
.replace(lessPath, replacer), encoding);
Expand All @@ -268,7 +269,7 @@ function babelify(js) {
}));
}

gulp.task('js', ['cleanCompile'], () => {
function babelify(modules) {
const streams = [];
const assets = gulp.src(['src/**/*.@(png|svg|less)']).pipe(gulp.dest('lib'));
if (glob.sync('src/' + '**/' + '*.{ts,tsx}').length) {
Expand Down Expand Up @@ -297,17 +298,25 @@ gulp.task('js', ['cleanCompile'], () => {
};
tsResult.on('finish', check);
tsResult.on('end', check);
const tsFiles = babelify(tsResult.js);
const tsd = tsResult.dts.pipe(gulp.dest('lib'));
streams.push(tsFiles);
streams.push(tsd);
streams.push.apply(streams, babelifyInternal(tsResult.js, modules));
streams.push(tsResult.dts.pipe(gulp.dest('lib')), tsResult.dts.pipe(gulp.dest('es')));
} else {
streams.push(babelify(gulp.src(['src/' + '**/' + '*.js', 'src/' + '**/' + '*.jsx'])));
streams.push.apply(streams,
babelifyInternal(gulp.src(['src/' + '**/' + '*.js', 'src/' + '**/' + '*.jsx']), modules));
}
return merge2(streams.concat([assets]));
}

gulp.task('js', ['cleanCompile'], () => {
return babelify();
});


gulp.task('es', ['js'], () => {
babelify(false);
});

gulp.task('compile', ['js', 'css']);
gulp.task('compile', ['es', 'css']);

gulp.task('check-deps', (done) => {
require('./checkDep')(done);
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-tools",
"version": "6.0.2",
"version": "6.0.3",
"description": "offline tools for react component",
"keywords": [
"react",
Expand Down Expand Up @@ -35,16 +35,17 @@
"babel-eslint": "^4.1.8",
"babel-loader": "^6.2.2",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-plugin-transform-runtime": "6.x",
"babel-preset-es2015-ie": "6.x",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"chalk": "~1.1.3",
"colorful": "2.x",
"commander": "2.8.x",
"console-polyfill": "~0.2.1",
"css-loader": "^0.9.1",
"es3ify": "^0.2.1",
"es5-shim": "4.x",
"es6-promise": "~3.2.1",
"eslint": "^1.10.3",
Expand Down

0 comments on commit 2c37699

Please sign in to comment.