選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

44 行
933 B

  1. module.exports = {
  2. name: "frappe-html",
  3. setup(build) {
  4. let path = require("path");
  5. let fs = require("fs/promises");
  6. build.onResolve({ filter: /\.html$/ }, args => {
  7. return {
  8. path: path.join(args.resolveDir, args.path),
  9. namespace: "frappe-html"
  10. };
  11. });
  12. build.onLoad({ filter: /.*/, namespace: "frappe-html" }, args => {
  13. let filepath = args.path;
  14. let filename = path.basename(filepath).split(".")[0];
  15. return fs
  16. .readFile(filepath, "utf-8")
  17. .then(content => {
  18. content = scrub_html_template(content);
  19. return {
  20. contents: `\n\tfrappe.templates['${filename}'] = \`${content}\`;\n`
  21. };
  22. })
  23. .catch(() => {
  24. return {
  25. contents: "",
  26. warnings: [
  27. {
  28. text: `There was an error importing ${filepath}`
  29. }
  30. ]
  31. };
  32. });
  33. });
  34. }
  35. };
  36. function scrub_html_template(content) {
  37. content = content.replace(/`/g, "\\`");
  38. return content;
  39. }