Skip to content

Commit 41d76a0

Browse files
committed
gulp build for style, scripts and umd
1 parent 5d0b0af commit 41d76a0

File tree

5 files changed

+606
-329
lines changed

5 files changed

+606
-329
lines changed

build.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

gulpfile.babel.js

Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,83 @@ import gulp from 'gulp';
22
import babel from 'gulp-babel';
33
import sass from 'gulp-sass';
44
import cleanCSS from 'gulp-clean-css';
5+
import cleanDir from 'gulp-clean';
56
import rename from 'gulp-rename';
6-
import rimraf from 'rimraf';
7-
import * as path from 'path';
8-
9-
gulp.task('default', ['prod']);
10-
11-
gulp.task('clean', () => {
12-
[
13-
path.join(__dirname, 'packages/react-bootstrap-table2/lib'),
14-
path.join(__dirname, 'packages/react-bootstrap-table2-editor/lib'),
15-
path.join(__dirname, 'packages/react-bootstrap-table2-filter/lib'),
16-
path.join(__dirname, 'packages/react-bootstrap-table2-overlay/lib'),
17-
path.join(__dirname, 'packages/react-bootstrap-table2-paginator/lib')
18-
].forEach((dir) => {
19-
rimraf.sync(dir);
20-
});
21-
});
22-
23-
gulp.task('build-js', () => {
24-
[
25-
'react-bootstrap-table2',
26-
'react-bootstrap-table2-editor',
27-
'react-bootstrap-table2-filter',
28-
'react-bootstrap-table2-overlay',
29-
'react-bootstrap-table2-paginator'
30-
].forEach((pkg) => {
31-
gulp.src([
32-
`./packages/${pkg}/**/*.js`,
33-
`!packages/${pkg}/+(test|dist|node_modules)/**/*.js`
7+
import shell from 'gulp-shell';
8+
9+
const LIB = 'lib';
10+
const DIST = 'dist';
11+
const TEST = 'test';
12+
const PKG_PATH = './packages';
13+
const NODE_MODULES = 'node_modules';
14+
15+
const JS_PKGS = [
16+
'react-bootstrap-table2',
17+
'react-bootstrap-table2-editor',
18+
'react-bootstrap-table2-filter',
19+
'react-bootstrap-table2-overlay',
20+
'react-bootstrap-table2-paginator'
21+
].reduce((pkg, curr) => `${curr}|${pkg}`, '');
22+
23+
const JS_SKIPS = `+(${TEST}|${LIB}|${DIST}|${NODE_MODULES})`;
24+
25+
const STYLE_PKGS = [
26+
'react-bootstrap-table2',
27+
'react-bootstrap-table2-paginator'
28+
].reduce((pkg, curr) => `${curr}|${pkg}`, '');
29+
30+
const STYLE_SKIPS = `+(${NODE_MODULES})`;
31+
32+
33+
function clean() {
34+
return gulp
35+
.src(`./packages/+(${JS_PKGS})/+(${LIB}|${DIST})`, { allowEmpty: true })
36+
.pipe(cleanDir());
37+
}
38+
39+
function scripts() {
40+
return gulp
41+
.src([
42+
`./packages/+(${JS_PKGS})/**/*.js`,
43+
`!packages/+(${JS_PKGS})/${JS_SKIPS}/**/*.js`
44+
])
45+
.pipe(babel())
46+
.pipe(rename((path) => {
47+
if (path.dirname.indexOf('src') > -1) {
48+
path.dirname = path.dirname.replace('src', `${LIB}/src`);
49+
} else {
50+
path.dirname += `/${LIB}`;
51+
}
52+
}))
53+
.pipe(gulp.dest(PKG_PATH));
54+
}
55+
56+
function styles() {
57+
return gulp
58+
.src([
59+
`./packages/+(${STYLE_PKGS})/style/**/*.scss`,
60+
`!packages/+(${STYLE_PKGS})/${STYLE_SKIPS}/**/*.scss`
3461
])
35-
.pipe(babel())
36-
.pipe(gulp.dest(`./packages/${pkg}/lib`));
37-
});
38-
});
39-
40-
gulp.task('build-sass', () => {
41-
[
42-
'react-bootstrap-table2',
43-
'react-bootstrap-table2-paginator'
44-
].forEach((pkg) => {
45-
gulp
46-
.src([
47-
`./packages/${pkg}/style/**/*.scss`,
48-
`!packages/${pkg}/+(dist|node_modules)/**/*.scss`
49-
])
50-
.pipe(sass().on('error', sass.logError))
51-
.pipe(gulp.dest(`./packages/${pkg}/dist`))
52-
.pipe(cleanCSS({ compatibility: 'ie8' }))
53-
.pipe(rename((path) => {
54-
path.extname = '.min.css';
55-
}))
56-
.pipe(gulp.dest(`./packages/${pkg}/dist`));
57-
});
58-
});
59-
60-
gulp.task('prod', ['clean', 'build-js', 'build-sass']);
62+
.pipe(sass().on('error', sass.logError))
63+
.pipe(rename((path) => {
64+
path.dirname = path.dirname.replace('style', DIST);
65+
}))
66+
.pipe(gulp.dest(PKG_PATH))
67+
.pipe(cleanCSS({ compatibility: 'ie8' }))
68+
.pipe(rename((path) => {
69+
path.extname = '.min.css';
70+
}))
71+
.pipe(gulp.dest(PKG_PATH));
72+
}
73+
74+
function umd() {
75+
return gulp.src('./webpack.prod.config.babel.js')
76+
.pipe(shell(['webpack --config <%= file.path %>']));
77+
}
78+
79+
const buildJS = gulp.parallel(umd, scripts);
80+
const buildCSS = styles;
81+
const build = gulp.series(clean, gulp.parallel(buildJS, buildCSS));
82+
83+
gulp.task('prod', build);
84+
gulp.task('default', build);

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"postinstall": "lerna bootstrap",
88
"publish": "lerna run build && lerna publish --silent",
9-
"build": "node -r babel-register build.js && ./node_modules/.bin/gulp prod",
9+
"build": "./node_modules/.bin/gulp prod",
1010
"start": "node -r babel-register ./node_modules/.bin/webpack-dev-server --config webpack.config.babel.js",
1111
"lint": "eslint ./packages --ext .js --ext .jsx --ignore-path .gitignore",
1212
"pretest": "yarn lint --cache",
@@ -46,11 +46,13 @@
4646
"eslint-plugin-import": "2.7.0",
4747
"eslint-plugin-jsx-a11y": "5.1.1",
4848
"eslint-plugin-react": "7.2.1",
49-
"gulp": "3.9.1",
49+
"gulp": "4.0.0",
5050
"gulp-babel": "7.0.0",
51+
"gulp-clean": "0.4.0",
5152
"gulp-clean-css": "3.9.2",
5253
"gulp-rename": "^1.2.2",
5354
"gulp-sass": "3.1.0",
55+
"gulp-shell": "0.6.5",
5456
"html-webpack-plugin": "2.30.1",
5557
"jest": "20.0.4",
5658
"jsdom": "11.2.0",
@@ -59,7 +61,6 @@
5961
"lerna-changelog": "^0.7.0",
6062
"node-sass": "4.5.3",
6163
"react-test-renderer": "16.0.0",
62-
"rimraf": "2.6.2",
6364
"sass-loader": "6.0.6",
6465
"sinon": "3.2.1",
6566
"style-loader": "0.17.0",

webpack.prod.config.babel.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import * as path from 'path';
22
import webpack from 'webpack';
33

4-
const sourceStylePath = path.join(__dirname, 'packages/react-bootstrap-table2/style');
5-
const paginationSourceStylePath = path.join(__dirname, 'packages/react-bootstrap-table2-paginator/style');
6-
74
module.exports = {
85
entry: {
9-
'react-bootstrap-table2/dist/react-bootstrap-table2': ['./packages/react-bootstrap-table2'],
10-
'react-bootstrap-table2/dist/react-bootstrap-table2.min': ['./packages/react-bootstrap-table2'],
11-
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor': ['./packages/react-bootstrap-table2-editor'],
12-
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor.min': ['./packages/react-bootstrap-table2-editor'],
13-
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter': ['./packages/react-bootstrap-table2-filter'],
14-
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min': ['./packages/react-bootstrap-table2-filter'],
15-
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay': ['./packages/react-bootstrap-table2-overlay'],
16-
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay.min': ['./packages/react-bootstrap-table2-overlay'],
17-
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator': ['./packages/react-bootstrap-table2-paginator'],
18-
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min': ['./packages/react-bootstrap-table2-paginator']
6+
'react-bootstrap-table2/dist/react-bootstrap-table2': './packages/react-bootstrap-table2/index.js',
7+
'react-bootstrap-table2/dist/react-bootstrap-table2.min': './packages/react-bootstrap-table2/index.js',
8+
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor': './packages/react-bootstrap-table2-editor/index.js',
9+
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor.min': './packages/react-bootstrap-table2-editor/index.js',
10+
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter': './packages/react-bootstrap-table2-filter/index.js',
11+
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min': './packages/react-bootstrap-table2-filter/index.js',
12+
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay': './packages/react-bootstrap-table2-overlay/index.js',
13+
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay.min': './packages/react-bootstrap-table2-overlay/index.js',
14+
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator': './packages/react-bootstrap-table2-paginator/index.js',
15+
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min': './packages/react-bootstrap-table2-paginator/index.js'
1916
},
2017
devtool: 'source-map',
2118
output: {
@@ -44,17 +41,11 @@ module.exports = {
4441
enforce: 'pre',
4542
test: /\.js?$/,
4643
exclude: /node_modules/,
47-
// include: [sourcePath],
4844
loader: 'eslint-loader'
4945
}, {
5046
test: /\.js?$/,
5147
use: ['babel-loader'],
5248
exclude: /node_modules/
53-
// include: [sourcePath]
54-
}, {
55-
test: /\.scss$/,
56-
use: ['style-loader', 'css-loader', 'sass-loader'],
57-
include: [sourceStylePath, paginationSourceStylePath]
5849
}]
5950
},
6051
plugins: [

0 commit comments

Comments
 (0)