builder.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import remarkGfm from "remark-gfm";
  2. import remarkTwemoji from "remark-twemoji";
  3. import remarkCodeSandbox from "remark-codesandbox";
  4. import remarkHint from "remark-hint";
  5. import remarkHtml from "remark-html";
  6. import remarkHighlight from "./plugins/remark-highlight.js";
  7. import { defaultSchema } from "hast-util-sanitize";
  8. import merge from "deepmerge";
  9. // Import the highlighter
  10. import prism from "prismjs";
  11. import "prismjs/components/prism-pug.js";
  12. import "prismjs/components/prism-javascript.js";
  13. import "prismjs/components/prism-sass.js";
  14. import "prismjs/components/prism-typescript.js";
  15. import webpack from "webpack";
  16. // Preserve className attributes when sanitizing the HTML
  17. // This is necessary for syntax highlighting
  18. const schema = merge(defaultSchema, {
  19. attributes: {
  20. span: ["className"],
  21. code: ["className"]
  22. }
  23. });
  24. /**
  25. * @see hints: https://github.com/sergioramos/remark-hint
  26. */
  27. const config = {
  28. entry: process.cwd() + "/src/index.js",
  29. output: {
  30. path: process.cwd() + "/dist",
  31. filename: "index.js",
  32. publicPath: "./"
  33. },
  34. cache: false,
  35. mode: "development",
  36. devtool: "source-map",
  37. module: {
  38. rules: [
  39. {
  40. test: /\.pupper$/,
  41. use: ["@pupperjs/webpack-loader"]
  42. },
  43. {
  44. test: /\.js$/,
  45. enforce: "pre",
  46. use: ["source-map-loader"],
  47. },
  48. {
  49. test: /\.md$/,
  50. use: [
  51. {
  52. loader: "html-loader",
  53. },
  54. {
  55. loader: "remark-loader",
  56. options: {
  57. remarkOptions: {
  58. plugins: [
  59. remarkTwemoji,
  60. remarkGfm,
  61. remarkCodeSandbox,
  62. remarkHint,
  63. [remarkHtml, {
  64. sanitize: false
  65. }],
  66. [remarkHighlight, {
  67. highlight: (code, language) => {
  68. const grammar = prism.languages[language];
  69. if (grammar) {
  70. code = prism.highlight(code, grammar);
  71. }
  72. return code;
  73. }
  74. }]
  75. ],
  76. },
  77. },
  78. },
  79. ],
  80. },
  81. ]
  82. }
  83. };
  84. const compiler = webpack(config);
  85. compiler.watch({
  86. aggregateTimeout: 300,
  87. poll: undefined
  88. }, (err, stats) => {
  89. if (err) {
  90. console.error(err.stack || err);
  91. if (err.details) {
  92. console.error(err.details);
  93. }
  94. return;
  95. }
  96. console.log(stats.toString({
  97. colors: true
  98. }));
  99. });