From e5bff38586f20ad7e34406dd2fa0f07d00697816 Mon Sep 17 00:00:00 2001 From: Michal Wolny Date: Fri, 9 Apr 2021 20:02:30 +0200 Subject: [PATCH] [dev-window-bootstrap] bring back window.bootstrap for umd, add esm build without it, add some package.json export fields --- gulpfile.js | 59 +++++++++++++++++++++++++++++++++++++++++--- package.json | 3 +++ src/js/tabler.esm.js | 10 ++++++++ src/js/tabler.js | 3 +++ 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/js/tabler.esm.js diff --git a/gulpfile.js b/gulpfile.js index 4c3ef743..954cf327 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -204,6 +204,7 @@ gulp.task('js', () => { plugins: [ rollupReplace({ 'process.env.NODE_ENV': JSON.stringify(BUILD ? 'production' : 'development'), + preventAssignment: false }), rollupBabel({ exclude: 'node_modules/**' @@ -239,6 +240,58 @@ gulp.task('js', () => { return g; }); +/** + * Compile JS module files to dist directory + */ +let cacheEsm; +gulp.task('mjs', () => { + const g = rollupStream({ + input: `${srcDir}/js/tabler.esm.js`, + cache: cacheEsm, + output: { + name: 'tabler.esm.js', + format: 'es', + exports: 'named' + }, + plugins: [ + rollupReplace({ + 'process.env.NODE_ENV': JSON.stringify(BUILD ? 'production' : 'development'), + preventAssignment: false + }), + rollupBabel({ + exclude: 'node_modules/**' + }), + nodeResolve(), + rollupCommonjs(), + rollupCleanup() + ] + }) + .on('bundle', (bundle) => { + cacheEsm = bundle; + }) + .pipe(vinylSource('tabler.esm.js')) + .pipe(vinylBuffer()) + .pipe(rename((path) => { + path.dirname = ''; + })) + .pipe(gulp.dest(`${distDir}/js/`)) + .pipe(browserSync.reload({ + stream: true, + })); + + if (BUILD) { + g.pipe(minifyJS({ + ext: { + src: '.js', + min: '.min.js' + }, + })) + .pipe(gulp.dest(`${distDir}/js/`)); + } + + return g; +}); + /** * Watch Jekyll files and build it to demo directory */ @@ -314,7 +367,7 @@ gulp.task('build-critical', (cb) => { */ gulp.task('watch', (cb) => { gulp.watch('./src/scss/**/*.scss', gulp.series('sass')); - gulp.watch('./src/js/**/*.js', gulp.series('js')); + gulp.watch('./src/js/**/*.js', gulp.series('js', 'mjs')); cb(); }); @@ -410,8 +463,8 @@ gulp.task('add-banner', () => { gulp.task('clean', gulp.series('clean-dirs', 'clean-jekyll')); -gulp.task('start', gulp.series('clean', 'sass', 'js', 'build-jekyll', gulp.parallel('watch-jekyll', 'watch', 'browser-sync'))); +gulp.task('start', gulp.series('clean', 'sass', 'js', 'mjs', 'build-jekyll', gulp.parallel('watch-jekyll', 'watch', 'browser-sync'))); -gulp.task('build-core', gulp.series('build-on', 'clean', 'sass', 'css-minify', 'js', 'copy-images', 'copy-libs', 'add-banner')); +gulp.task('build-core', gulp.series('build-on', 'clean', 'sass', 'css-minify', 'js', 'mjs', 'copy-images', 'copy-libs', 'add-banner')); gulp.task('build-demo', gulp.series('build-on', 'build-jekyll', 'copy-static', 'copy-dist', 'build-cleanup', 'build-purgecss'/*, 'build-critical'*/)); gulp.task('build', gulp.series('build-core', 'build-demo')); diff --git a/package.json b/package.json index 7e146b51..a21997bb 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,9 @@ ], "style": "dist/css/tabler.css", "sass": "src/scss/tabler.scss", + "unpkg": "dist/js/tabler.min.js", + "umd:main": "dist/js/tabler.min.js", + "module": "dist/js/tabler.esm.js", "main": "dist/js/tabler.js", "homepage": "https://tabler.io", "devDependencies": { diff --git a/src/js/tabler.esm.js b/src/js/tabler.esm.js new file mode 100644 index 00000000..c0e60582 --- /dev/null +++ b/src/js/tabler.esm.js @@ -0,0 +1,10 @@ +//Vendor + +import './src/autosize'; +import './src/input-mask'; +import './src/dropdown'; +import './src/tooltip'; +import './src/popover'; +import './src/switch-icon'; +import './src/toast'; + diff --git a/src/js/tabler.js b/src/js/tabler.js index c0e60582..5d274cee 100644 --- a/src/js/tabler.js +++ b/src/js/tabler.js @@ -7,4 +7,7 @@ import './src/tooltip'; import './src/popover'; import './src/switch-icon'; import './src/toast'; +import * as bootstrap from 'bootstrap'; + +window.bootstrap = bootstrap; -- GitLab