Skip to content

Commit

Permalink
Merge pull request #106 from marp-team/optimized-default-theme
Browse files Browse the repository at this point in the history
Optimize default theme CSS on build time
  • Loading branch information
yhatt authored Sep 12, 2019
2 parents 27a5775 + d0a4a43 commit ad01abd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand All @@ -28,6 +29,7 @@ const plugins = [
],
},
plugins: [
postcssOptimizeDefaultTheme(),
postcssUrl({
filter: '**/assets/**/*.svg',
encodeType: 'base64',
Expand Down
20 changes: 20 additions & 0 deletions scripts/postcss-optimize-default-theme.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ad01abd

Please sign in to comment.