fix(v2): only import prism css on browser

This commit is contained in:
endiliey 2019-04-14 01:02:34 +08:00
parent f37300a69b
commit 261ab9254d
2 changed files with 8 additions and 2 deletions

View file

@ -2,7 +2,7 @@
Docusaurus webpack loader of [MDX](https://github.com/mdx-js/mdx)
The extra idea here is to simplify things by adding prismjs syntax highlighting by default through https://github.com/mapbox/rehype-prism and add the prism css theme import directly.
The extra idea here is to simplify things by adding prismjs syntax highlighting by default through https://github.com/mapbox/rehype-prism and add the prism css theme import directly (only add the CSS import if target is 'web').
## Installation

View file

@ -27,10 +27,16 @@ module.exports = async function(content) {
return callback(err);
}
let importStr = '';
// If webpack target is web, we can import the css
if (this.target === 'web') {
importStr = `import '${options.prismTheme}';`;
}
const code = `
import React from 'react';
import { mdx } from '@mdx-js/react';
import '${options.prismTheme}';
${importStr}
${result}
`;