Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize default theme CSS on build time #106

Merged
merged 2 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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