Skip to content

Commit c78ae5f

Browse files
tibing-old-emailnnixaa
authored andcommitted
fix(scripts): add moment and date-fns bundles (#818)
1 parent c3c755a commit c78ae5f

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

scripts/gulp/tasks/bundle/bundle.ts

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,30 @@ const rollup = require('gulp-rollup');
66
const rename = require('gulp-rename');
77
const replace = require('gulp-replace');
88

9-
task('bundle', ['bundle:umd:theme', 'bundle:umd:auth', 'bundle:umd:security']);
10-
task('bundle:umd:theme', bundleUmdTheme);
11-
task('bundle:umd:auth', bundleUmdAuth);
12-
task('bundle:umd:security', bundleUmdSecurity);
9+
task('bundle', [
10+
'bundle:umd:theme',
11+
'bundle:umd:auth',
12+
'bundle:umd:security',
13+
'bundle:umd:moment',
14+
'bundle:umd:date-fns',
15+
]);
16+
17+
task('bundle:umd:theme', () => bundleUmdModule('theme'));
18+
task('bundle:umd:auth', () => bundleUmdModule('auth'));
19+
task('bundle:umd:security', () => bundleUmdModule('security'));
20+
task('bundle:umd:moment', () => bundleUmdModule('moment'));
21+
task('bundle:umd:date-fns', () => bundleUmdModule('date-fns'));
1322
task('bundle:rename-dev', bundleRenameDev);
1423

15-
function bundleUmdTheme() {
16-
const config = {
17-
src: `${LIB_DIR}/theme/**/*.js`,
18-
moduleName: 'nb.theme',
19-
entry: `${LIB_DIR}/theme/index.js`,
24+
function bundleUmdModule(name: string) {
25+
bundle({
26+
src: `${LIB_DIR}/${name}/**/*.js`,
27+
moduleName: `nb.${name}`,
28+
entry: `${LIB_DIR}/${name}/index.js`,
2029
format: 'umd',
21-
output: 'theme.umd.js',
22-
dest: `${LIB_DIR}/theme/bundles`,
23-
};
24-
25-
bundle(config);
26-
}
27-
28-
function bundleUmdAuth() {
29-
const config = {
30-
src: `${LIB_DIR}/auth/**/*.js`,
31-
moduleName: 'nb.auth',
32-
entry: `${LIB_DIR}/auth/index.js`,
33-
format: 'umd',
34-
output: 'auth.umd.js',
35-
dest: `${LIB_DIR}/auth/bundles`,
36-
};
37-
38-
bundle(config);
39-
}
40-
41-
function bundleUmdSecurity() {
42-
const config = {
43-
src: `${LIB_DIR}/security/**/*.js`,
44-
moduleName: 'nb.security',
45-
entry: `${LIB_DIR}/security/index.js`,
46-
format: 'umd',
47-
output: 'security.umd.js',
48-
dest: `${LIB_DIR}/security/bundles`,
49-
};
50-
51-
bundle(config);
30+
output: `${name}.umd.js`,
31+
dest: `${LIB_DIR}/${name}/bundles`,
32+
});
5233
}
5334

5435
function bundle(config: any) {

scripts/gulp/tasks/bundle/rollup-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ const ROLLUP_GLOBALS = {
3030
// 3rd party dependencies
3131
'intersection-observer': 'intersection-observer',
3232

33+
// date libs for date service
34+
'moment': 'moment',
35+
'date-fns/parse': 'date-fns.parse',
36+
3337
// @nebular dependencies
3438
'@nebular/theme': 'nb.theme',
3539
'@nebular/auth': 'nb.auth',
3640
'@nebular/security': 'nb.security',
41+
'@nebular/moment': 'nb.moment',
42+
'@nebular/date-fns': 'nb.date-fns',
3743
};
3844

3945
export const ROLLUP_COMMON_CONFIG = {

src/framework/date-fns/services/date-fns-date.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { Inject, Injectable, LOCALE_ID } from '@angular/core';
88

99
import { NbNativeDateService } from '@nebular/theme';
1010

11-
import * as parse from 'date-fns/parse';
11+
import * as dateFnsParse from 'date-fns/parse';
12+
// @ts-ignore
13+
import { default as rollupParse} from 'moment';
14+
15+
const parse = rollupParse || dateFnsParse;
1216

1317

1418
@Injectable()

src/framework/moment/services/moment-date.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import { TranslationWidth } from '@angular/common';
99

1010
import { NbDateService } from '@nebular/theme';
1111

12-
import * as moment from 'moment';
13-
import { Moment } from 'moment';
12+
import * as _moment from 'moment';
13+
// @ts-ignore
14+
import { default as _rollupMoment, Moment } from 'moment';
15+
16+
const moment = _rollupMoment || _moment;
1417

1518

1619
@Injectable()

0 commit comments

Comments
 (0)