-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.js
66 lines (64 loc) · 2.01 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const fs = require("fs");
const path = require("path");
const hljs = require("highlight.js");
const anchor = require("markdown-it-anchor");
const footnote = require("markdown-it-footnote");
const markdownIt = require("markdown-it")({
highlight: (str, lang) => hljs.highlight(str, { language: lang }).value,
});
markdownIt.use(footnote);
markdownIt.use(anchor, {
permalink: anchor.permalink.headerLink({ safariReaderFix: true }),
});
const srcDirPath = path.resolve(__dirname, "src");
const srcMarkdownFilePath = path.join(
srcDirPath,
"google-typescript-style-guide-ru.md"
);
const title = `Руководство Google по стилю написания кода
на языке TypeScript (перевод)`;
const menuTitle = "Содержание";
const canonicalLink = "https://olegbarabanov.github.io/google-typescript-style-guide-ru/";
module.exports = {
cache: false,
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
plugins: [
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
favicon: path.join(srcDirPath, "favicon.ico"),
template: path.join(srcDirPath, "template.html"),
}),
new webpack.DefinePlugin({
title: JSON.stringify(title),
menuTitle: JSON.stringify(menuTitle),
canonicalLink: JSON.stringify(canonicalLink),
content: webpack.DefinePlugin.runtimeValue(
() => {
const markdown = fs.readFileSync(srcMarkdownFilePath);
const html = markdownIt.render(markdown.toString());
return JSON.stringify(html);
},
{
fileDependencies: [srcMarkdownFilePath],
}
),
}),
],
resolve: {
// FIXME: see Primer.css bug https://github.com/primer/css/issues/442
alias: {
"/images/spinners": false,
"/images/modules": false,
},
},
};