This is my webpack config:
// Generated using webpack-cli https://github.com/webpack/webpack-cli
import path from "path";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CopyPlugin from "copy-webpack-plugin";
//@ts-ignore
import rehype from "rehype-autolink-headings";
const isProduction = process.env.NODE_ENV == "production";
const stylesHandler = isProduction
? MiniCssExtractPlugin.loader
: "style-loader";
const config = {
entry: "./src/index.tsx",
output: {
path: path.resolve("./", "build"),
publicPath: "/",
},
devServer: {
open: true,
host: "localhost",
historyApiFallback: true,
},
plugins: [
new HtmlWebpackPlugin({
template: "index.html",
}),
new CopyPlugin({
patterns: [{ from: "public", to: "./" }],
}),
// Add your plugins here
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
],
module: {
rules: [
// `js` and `jsx` files are parsed using `babel`
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
// `ts` and `tsx` files are parsed using `ts-loader`
{
test: /\.(ts|tsx)$/,
loader: "ts-loader",
},
{
test: /\.mdx?$/,
use: [
{
loader: "@mdx-js/loader",
/** @type {import('@mdx-js/loader').Options} */
options: {
rehypePlugins: [rehype({ behavior: "after" })],
},
},
],
},
{
test: /\.css$/i,
use: [stylesHandler, "css-loader"],
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: "asset",
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js", "..."],
},
};
export default () => {
if (isProduction) {
//@ts-ignore
config.mode = "production";
//@ts-ignore
config.plugins.push(new MiniCssExtractPlugin());
} else {
//@ts-ignore
config.mode = "development";
}
return config;
};
As you might have noticed, I am using mdx-js and rehype-autolink-headings.
However using rehype-autolink-headings does not affect heading, I mean heading are compiled without links and ID's.
What I am doing wrong ?