-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.client.config.base.js
92 lines (85 loc) · 6.53 KB
/
webpack.client.config.base.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const path = require("path");
process.env.NODE_CONFIG_DIR = path.join(__dirname, "../../config");
const fs = require("fs");
const config = require("config");
const express = require("express");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpackBaseConfig = require("../../webpack.client.config.base");
const publicPath = `${config.get("www.assetUrl")}/`;
const sources = [
"*.md",
path.resolve(require.resolve("@fortawesome/fontawesome-free"), "../../webfonts/*")
];
if (process.env.NODE_ENV && fs.existsSync(path.resolve(require.resolve("@randy.tarampi/assets"), "../assets/web", process.env.NODE_ENV, "*"))) {
const environmentAssetsPath = path.resolve(require.resolve("@randy.tarampi/assets"), "../assets/web", process.env.NODE_ENV, "*");
if (fs.existsSync(environmentAssetsPath)) {
sources.push(environmentAssetsPath);
}
} else {
sources.push(path.resolve(require.resolve("@randy.tarampi/assets"), "../../assets/web/*"));
}
const buildViewForPageUrl = (pageName, pageUrl = config.get("www.publishUrl")) => {
const packageJson = require("./package.json");
const {buildPugLocals} = require("@randy.tarampi/views");
return new HtmlWebpackPlugin({
filename: `${pageName}.html`,
template: path.resolve(require.resolve("@randy.tarampi/views"), "../../templates/index.pug"),
templateParameters: buildPugLocals({
bundleName: config.get("www.bundle.name"),
esmBundleName: `${config.get("www.bundle.name")}.esm`,
serviceWorkerInstallerBundleName: config.get("www.bundle.swInstaller"),
packageJson,
pageUrl,
injectedScript: [
`<script>window.$crisp=[];window.CRISP_WEBSITE_ID="${config.get("crisp.app.id")}";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();</script>`
].join(""),
injectedNoScript: [
`<noscript>
<div class="error"><div class="row"><div class="col"><div id="error-dis-bear" class="bear bear--ʕಠᴥಠʔ"><span data-metrics-event-name="emoji-component" data-metrics-type="onClick" data-metrics-name="error-dis-bear__leftEar" data-metrics-label="ʕ" data-metrics-value="" class="error-dis-bear__leftEar bear__leftEar bear__leftEar--ʕಠᴥಠʔ">ʕ</span><span data-metrics-event-name="emoji-component" data-metrics-type="onClick" data-metrics-name="error-dis-bear__leftEye" data-metrics-label="ಠ" data-metrics-value="" class="error-dis-bear__leftEye bear__leftEye bear__leftEye--ʕಠᴥಠʔ">ಠ</span><span data-metrics-event-name="emoji-component" data-metrics-type="onClick" data-metrics-name="error-dis-bear__nose" data-metrics-label="ᴥ" data-metrics-value="" class="error-dis-bear__nose bear__nose bear__nose--ʕಠᴥಠʔ">ᴥ</span><span data-metrics-event-name="emoji-component" data-metrics-type="onClick" data-metrics-name="error-dis-bear__rightEye" data-metrics-label="ಠ" data-metrics-value="" class="error-dis-bear__rightEye bear__rightEye bear__rightEye--ʕಠᴥಠʔ">ಠ</span><span data-metrics-event-name="emoji-component" data-metrics-type="onClick" data-metrics-name="error-dis-bear__rightEar" data-metrics-label="ʔ" data-metrics-value="" class="error-dis-bear__rightEar bear__rightEar bear__rightEar--ʕಠᴥಠʔ">ʔ</span><div class="bear__children bear__children--ʕಠᴥಠʔ"><h2 class="error__message--header"><span class="text">Get with the times</span></h2><p class="error__message">You'll need to enable JavaScript to enjoy this page. <a target="_self" rel="noopener noreferrer" data-metrics-event-name="anchor" data-metrics-type="href" data-metrics-name="Shoot me a message" data-metrics-label="Shoot me a message" data-metrics-value="mailto:[email protected]?subject=Hey%2C%20I%20browse%20with%20JavaScript%20disabled" subject="Hey, I browse with JavaScript disabled" email="[email protected]" class="link link--email link--no-branding" href="mailto:[email protected]?subject=Hey%2C%20I%20browse%20with%20JavaScript%20disabled" text="[email protected]">Shoot me a message</a> if you're super keen or just <a target="__blank" rel="noopener noreferrer" data-metrics-event-name="anchor" data-metrics-type="href" data-metrics-name="download my resume" data-metrics-label="download my resume" data-metrics-value="https://github.com/randytarampi/me.resume/raw/master/a4.pdf?utm_campaign=&utm_content=&utm_medium=referral&utm_source=&utm_term=download%20my%20resume" text="download my resume" class="link link--campaign" href="https://github.com/randytarampi/me.resume/raw/master/a4.pdf?utm_campaign=&utm_content=&utm_medium=referral&utm_source=&utm_term=download%20my%20resume">download my resume</a>.</p></div></div></div></div></div>
</noscript>`
]
}),
alwaysWriteToDisk: true,
excludeChunks: [
"styles",
"vendor",
config.get("www.bundle.name"),
`${config.get("www.bundle.swInstaller")}`,
"vendor.esm",
`${config.get("www.bundle.name")}.esm`,
`${config.get("www.bundle.swInstaller")}.esm`
]
});
};
const views = [
["index"],
["404"],
["blog", `${config.get("www.publishUrl")}${config.get("www.postsUrl")}`],
["photos", `${config.get("www.publishUrl")}${config.get("www.photosUrl")}`],
["words", `${config.get("www.publishUrl")}${config.get("www.wordsUrl")}`],
["resume", `${config.get("www.publishUrl")}${config.get("www.resumeUrl")}`],
["letter", `${config.get("www.publishUrl")}${config.get("www.letterUrl")}`],
["map", `${config.get("www.publishUrl")}${config.get("www.mapUrl")}`]
];
module.exports = ({plugins, ...overrides}) => webpackBaseConfig({
publicPath: publicPath,
sourceDirectoryPath: __dirname,
compliationDirectoryPath: path.join(__dirname, "dist"),
webpackDevServerMiddleware: [
(app) => app.use("/api/resume", express.static("./src/resumes")),
(app) => app.use("/api/letter", express.static("./src/letters")),
],
plugins: plugins
.concat(new CopyWebpackPlugin({
patterns: sources.map(source => ({
from: source,
to: "[name].[ext]",
context: source.match(/^node_modules/)
? "../../"
: undefined
}))
}))
.concat(views.map(([pageName, pageUrl]) => buildViewForPageUrl(pageName, pageUrl))),
...overrides
});