From 261ab9254dc75e199a868b74dcd219c479bcb2d6 Mon Sep 17 00:00:00 2001 From: endiliey Date: Sun, 14 Apr 2019 01:02:34 +0800 Subject: [PATCH] fix(v2): only import prism css on browser --- packages/docusaurus-mdx-loader/README.md | 2 +- packages/docusaurus-mdx-loader/src/index.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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} `;