From 5e61edd6d7750adf6c86f20bde48c562204633b3 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Thu, 12 Sep 2019 10:36:27 +0900 Subject: [PATCH 1/2] Optimize style of default theme on build time --- rollup.config.js | 2 ++ scripts/postcss-optimize-default-theme.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 scripts/postcss-optimize-default-theme.js diff --git a/rollup.config.js b/rollup.config.js index 8f900516..d2f5c38f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,6 +8,7 @@ import postcss from 'rollup-plugin-postcss' import { terser } from 'rollup-plugin-terser' import typescript from 'rollup-plugin-typescript' import pkg from './package.json' +import postcssOptimizeDefaultTheme from './scripts/postcss-optimize-default-theme' const plugins = [ json({ preferConst: true }), @@ -28,6 +29,7 @@ const plugins = [ ], }, plugins: [ + postcssOptimizeDefaultTheme(), postcssUrl({ filter: '**/assets/**/*.svg', encodeType: 'base64', diff --git a/scripts/postcss-optimize-default-theme.js b/scripts/postcss-optimize-default-theme.js new file mode 100644 index 00000000..b01d512e --- /dev/null +++ b/scripts/postcss-optimize-default-theme.js @@ -0,0 +1,20 @@ +import postcss from 'postcss' + +const defaultThemeMatcher = /@theme +default/ + +const plugin = postcss.plugin('postcss-optimize-default-theme', () => css => { + if (!defaultThemeMatcher.test(css.source.input.css)) return + + // Remove rules for .markdown-body selector + css.walkRules(rule => { + const ss = rule.selectors.filter(s => !s.startsWith('.markdown-body')) + + if (ss.length > 0) { + rule.selectors = ss + } else { + rule.remove() + } + }) +}) + +export default plugin From d0a4a436a52c79a13f0362207a3285165daa5ffa Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Thu, 12 Sep 2019 10:47:21 +0900 Subject: [PATCH 2/2] [ci skip] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0cf3f3b..46694937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Add `minifyCSS` option ([#103](https://github.com/marp-team/marp-core/pull/103)) - Add `dollarPrefixForGlobalDirectives` option _(not for users)_ ([#104](https://github.com/marp-team/marp-core/pull/104)) +### Fixed + +- Optimize default theme CSS by removing `.markdown-body` selector on build time ([#106](https://github.com/marp-team/marp-core/pull/106)) + ### Changed - Update CircleCI configuration to use v2.1 ([#101](https://github.com/marp-team/marp-core/pull/101))