-
I've installed the import { addAfterLoader, loaderByName } from '@craco/craco'
import remarkGfm from 'remark-gfm'
export default {
webpack: {
configure: (webpackConfig) => {
addAfterLoader(webpackConfig, loaderByName('babel-loader'), {
test: /\.(md|mdx)$/,
loader: '@mdx-js/loader',
/** @type {import('@mdx-js/loader').Options} */
options: {
remarkPlugins: [
remarkGfm,
]
}
})
return webpackConfig
}
}
} Now,
My {
"compilerOptions": {
"target": "es5",
"downlevelIteration": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"noEmit": true,
"baseUrl": "src",
"noFallthroughCasesInSwitch": false,
"types": [
"cypress",
"cypress-react-selector",
"cypress-react-router",
"mdx"
],
},
"include": [
"src/",
"styleguidist/"
]
} What am I doing wrong? I'm already import'ing from the .ts configuration file. What am I missing here? Is MDX really extensible using plugins when using CRA 5 and CRACO 5? Or should there be a big warning in the documentation that many plugins won't work at all in this setup? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
From your comment in https://github.com/orgs/mdx-js/discussions/2217#discussioncomment-4621685 It sounds like you are holding back on a prerelease of MDX? On the topic of ESM. |
Beta Was this translation helpful? Give feedback.
-
For the record, here's what I tried using the above installed (recent) npm package versions with a const { addAfterLoader, loaderByName } = require('@craco/craco')
module.exports = {
webpack: {
configure: (webpackConfig) => {
addAfterLoader(webpackConfig, loaderByName('babel-loader'), {
test: /\.(md|mdx)$/,
loader: require.resolve('@mdx-js/loader'),
/** @type {import('@mdx-js/loader').Options} */
options: {
providerImportSource: require.resolve('@mdx-js/react'),
remarkPlugins: [
require.resolve('remark-gfm'),
],
}
})
return webpackConfig
}
}
} This fails as follows:
Trying to require at the top: const { addAfterLoader, loaderByName } = require('@craco/craco')
const { remarkGfm } =require('remark-gfm')
module.exports = {
webpack: {
configure: (webpackConfig) => {
addAfterLoader(webpackConfig, loaderByName('babel-loader'), {
test: /\.(md|mdx)$/,
loader: require.resolve('@mdx-js/loader'),
/** @type {import('@mdx-js/loader').Options} */
options: {
providerImportSource: require.resolve('@mdx-js/react'),
remarkPlugins: [
remarkGfm,
],
}
})
return webpackConfig
}
}
} thows this error:
|
Beta Was this translation helpful? Give feedback.
-
That took only ... what? ... roundabout half a year for me to finally crack open (taking several aborted attempts into consideration). I'm still not exactly thrilled by what looks to me like an official endorsing of CRACO in the MDX documentation and then in Q&A's to point fingers at it that it breaks all things in this complex ecosystem (house of cards). Hopefully, my solution might even serve for the official documentation and can put the unnecessary and unhelpful finger pointing to its final rest in the future. Anyway, here's a more elaborate example that works for me now and basically replaces the mdx-loader npm package (please don't confuse this with
const { addAfterLoader, loaderByName } = require('@craco/craco')
module.exports = async (env) => {
const remarkGfm = (await import('remark-gfm')).default
const remarkImages = (await import('remark-images')).default
const remarkTextr = (await import('remark-textr')).default
const rehypeSlug = (await import('rehype-slug')).default
const textrTypoApos = (await import('typographic-apostrophes')).default
const textrTypoQuotes = (await import('typographic-quotes')).default
const textrTypoPossPluralsApos = (await import('typographic-apostrophes-for-possessive-plurals')).default
const textrTypoEllipses = (await import('typographic-ellipses')).default
const textrTypoEmDashes = (await import('typographic-em-dashes')).default
const textrTypoEnDashes = (await import('typographic-en-dashes')).default
return {
webpack: {
configure: (webpackConfig) => {
addAfterLoader(webpackConfig, loaderByName('babel-loader'), {
test: /\.(md|mdx)$/,
loader: require.resolve('@mdx-js/loader'),
/** @type {import('@mdx-js/loader').Options} */
options: {
remarkPlugins: [
remarkGfm,
remarkImages,
[remarkTextr, {
plugins: [
textrTypoApos,
textrTypoQuotes,
textrTypoPossPluralsApos,
textrTypoEllipses,
// textrTypoEmDashes,
textrTypoEnDashes,
],
options: {
locale: 'en-us'
}
}],
],
rehypePlugins: [
rehypeSlug,
],
}
})
return webpackConfig
}
}
}
} PS: please let the Q authors themselves decide on whether an A actually solves the Q and don't preempt the Q author's decision. Thank you very much. |
Beta Was this translation helpful? Give feedback.
That took only ... what? ... roundabout half a year for me to finally crack open (taking several aborted attempts into consideration). I'm still not exactly thrilled by what looks to me like an official endorsing of CRACO in the MDX documentation and then in Q&A's to point fingers at it that it breaks all things in this complex ecosystem (house of cards). Hopefully, my solution might even serve for the official documentation and can put the unnecessary and unhelpful finger pointing to its final rest in the future.
Anyway, here's a more elaborate example that works for me now and basically replaces the mdx-loader npm package (please don't confuse this with
@mdx-js/loader
!) -- that 3rd part…