-
Notifications
You must be signed in to change notification settings - Fork 75
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
Issues when using esbuild plugins #116
Comments
By default It is easy enough to fix, if you take a look at my esbuildOptions I'm using an output directory so it can write images to a path. You need to define |
Hey, sorry for the super late response. I played around a few times to try and get it to work, and I think I'm very close, I just need the right loader for .scss files. My esbuild configuration: const { code } = await bundleMDX(source, {
cwd: folder,
esbuildOptions: options => {
// For some reason, the default of `es5` gives errors. Oh well.
options.target = 'es2020';
// Load the sass plugin (import { sassPlugin } from 'esbuild-sass-plugin')
if (options.plugins) options.plugins = [
...options.plugins,
sassPlugin({
basedir: '.'
}),
];
// Add a loder for .scss files
options.loader = {
...options.loader,
'.scss': '???' // I'm unsure as to what type to use here. 'css' throws errors and 'file' just copies over the .scss file
}
options.publicPath = '/mdx';
// path.join(process.cwd(), 'public/mdx');
options.outdir = outputFolder;
options.write = true;
return options;
}
}); The React component throwing the error import { useState } from 'react'
import pageStyles from '../styles/components/PostLink.module.scss'
/**
* Link to a post
*/
const PostLink = (props: { slug: string }) => {
const [post, setPost] = useState(); // To be used later
return (<p className={pageStyles.cardSubtitle}>Some text</p>);
}
export default PostLink I'm unsure on what to put for the .scss loader. Thank you for your help |
I'd suggest moving the SASS plugin to the top of the plugin list (before |
I managed to make it work with mdx-loader, by adding webpack(config, options) {
config.module.rules.push({
test: /\.mdx?$/,
use: [
// The default `babel-loader` used by Next:
options.defaultLoaders.babel,
{
loader: '@mdx-js/loader',
/** @type {import('@mdx-js/loader').Options} */
options: {/* jsxImportSource: …, otherOptions… */}
}
]
});
return config
} to next.config.js and using it with dynamic imports like so // Your path will vary
const Component = dynamic(() => import(`../../../blog/${frontmatter.slug}/index.mdx`));
return (<NextPage>
<Component /> {/* The important bit */}
</NextPage>) |
If you encounter this issue. Pass it like this into
|
mdx-bundler
version: ^6.0.2node
version: v16.2.0npm
version: 7.20.5Relevant code or config
What you did:
I tried two other plugins for using Sass with esbuild, but they all had a similar error.
What happened:
Console output:
Reproduction repository:
https://github.com/GunnerBasil/mdx-bundler-sass-plugins-issue
Problem description:
When using
esbuild-plugin-sass
withmdx-bundler
,mdx-bundler
oresbuild
output an error about not being able to import the temporary file generated byesbuild-plugin-sass
without configuring an output path.Suggested solution:
If what I am doing is incorrect, it would be helpful to elaborate in the documentation on how to use plugins.
The text was updated successfully, but these errors were encountered: