From 7fa01c7333ebaec2f07de7cd9b6bd838a974ee4a Mon Sep 17 00:00:00 2001 From: Sergey Makhnatkin Date: Tue, 22 Oct 2024 13:36:44 +0200 Subject: [PATCH] feat(dist): export css and js without tabs and cuts (#540) --- esbuild/build.mjs | 76 ++++++++++++++++++++++++++++++++++------- src/js/_yfm-only.ts | 1 + src/js/base.ts | 2 ++ src/js/index.ts | 5 ++- src/scss/_yfm-only.scss | 12 +++++++ src/scss/base.scss | 4 +++ src/scss/yfm.scss | 11 ++---- 7 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 src/js/_yfm-only.ts create mode 100644 src/js/base.ts create mode 100644 src/scss/_yfm-only.scss create mode 100644 src/scss/base.scss diff --git a/esbuild/build.mjs b/esbuild/build.mjs index 8812d4e7..b33cf1fb 100755 --- a/esbuild/build.mjs +++ b/esbuild/build.mjs @@ -51,6 +51,20 @@ const common = { format: 'iife', plugins, }), + build({ + ...common, + entryPoints: ['src/scss/base.scss'], + outfile: 'dist/css/base.css', + format: 'iife', + plugins, + }), + build({ + ...common, + entryPoints: ['src/scss/_yfm-only.scss'], + outfile: 'dist/css/_yfm-only.css', + format: 'iife', + plugins, + }), build({ ...common, entryPoints: ['src/scss/print.scss'], @@ -60,12 +74,26 @@ const common = { }), ]); - await build({ - ...common, - entryPoints: ['dist/css/yfm.css'], - outfile: 'dist/css/yfm.min.css', - minify: true, - }); + await Promise.all([ + build({ + ...common, + entryPoints: ['dist/css/yfm.css'], + outfile: 'dist/css/yfm.min.css', + minify: true, + }), + build({ + ...common, + entryPoints: ['dist/css/base.css'], + outfile: 'dist/css/base.min.css', + minify: true, + }), + build({ + ...common, + entryPoints: ['dist/css/_yfm-only.css'], + outfile: 'dist/css/_yfm-only.min.css', + minify: true, + }), + ]); })(); (async function buildJs() { @@ -75,6 +103,16 @@ const common = { entryPoints: ['src/js/index.ts'], outfile: 'dist/js/yfm.js', }), + build({ + ...common, + entryPoints: ['src/js/base.ts'], + outfile: 'dist/js/base.js', + }), + build({ + ...common, + entryPoints: ['src/js/_yfm-only.ts'], + outfile: 'dist/js/_yfm-only.js', + }), build({ ...common, entryPoints: ['src/js/print/index.ts'], @@ -82,10 +120,24 @@ const common = { }), ]); - await build({ - ...common, - entryPoints: ['dist/js/yfm.js'], - outfile: 'dist/js/yfm.min.js', - minify: true, - }); + await Promise.all([ + build({ + ...common, + entryPoints: ['dist/js/yfm.js'], + outfile: 'dist/js/yfm.min.js', + minify: true, + }), + build({ + ...common, + entryPoints: ['dist/js/base.js'], + outfile: 'dist/js/base.min.js', + minify: true, + }), + build({ + ...common, + entryPoints: ['dist/js/_yfm-only.js'], + outfile: 'dist/js/_yfm-only.min.js', + minify: true, + }), + ]); })(); diff --git a/src/js/_yfm-only.ts b/src/js/_yfm-only.ts new file mode 100644 index 00000000..7af3a58a --- /dev/null +++ b/src/js/_yfm-only.ts @@ -0,0 +1 @@ +import './term'; diff --git a/src/js/base.ts b/src/js/base.ts new file mode 100644 index 00000000..8fe8d245 --- /dev/null +++ b/src/js/base.ts @@ -0,0 +1,2 @@ +import './polyfill'; +import './code'; diff --git a/src/js/index.ts b/src/js/index.ts index 13aaabb8..7d615414 100644 --- a/src/js/index.ts +++ b/src/js/index.ts @@ -1,8 +1,7 @@ import '@diplodoc/cut-extension/runtime'; import '@diplodoc/tabs-extension/runtime'; -import './polyfill'; -import './code'; -import './term'; +import './base'; +import './_yfm-only'; import './wide-mode'; import './patch'; diff --git a/src/scss/_yfm-only.scss b/src/scss/_yfm-only.scss new file mode 100644 index 00000000..acd5bc81 --- /dev/null +++ b/src/scss/_yfm-only.scss @@ -0,0 +1,12 @@ +/** + Note: This file excludes "cut" and "tabs" as they are handled separately + in dedicated extensions (packages). In the future, "note", "file", "term" + and "table" will also be excluded from this file and moved to yfm.scss, + once they are moved to separate packages. Direct usage is not recommended, + as the file is subject to changes without prior notice. + */ + +@import 'note'; +@import 'file'; +@import 'table'; +@import 'term'; diff --git a/src/scss/base.scss b/src/scss/base.scss new file mode 100644 index 00000000..d865c1fc --- /dev/null +++ b/src/scss/base.scss @@ -0,0 +1,4 @@ +@import 'common'; +@import 'anchor'; +@import 'highlight'; +@import 'code'; diff --git a/src/scss/yfm.scss b/src/scss/yfm.scss index 474aff24..24b79e70 100644 --- a/src/scss/yfm.scss +++ b/src/scss/yfm.scss @@ -1,12 +1,5 @@ -@import 'common'; -@import 'note'; -@import 'anchor'; -@import 'highlight'; -@import 'code'; -@import 'file'; -@import 'term'; -@import 'table'; +@import 'base'; +@import 'yfm-only'; @import 'modal'; - @import '@diplodoc/cut-extension/runtime'; @import '@diplodoc/tabs-extension/runtime';