diff --git a/packages/docusaurus-mdx-loader/README.md b/packages/docusaurus-mdx-loader/README.md index c7b87817c1..8fc5bbb40b 100644 --- a/packages/docusaurus-mdx-loader/README.md +++ b/packages/docusaurus-mdx-loader/README.md @@ -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 diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index b6c819523a..fccd69b6eb 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -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} `;