-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
161 lines (157 loc) · 5.17 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import fs from "node:fs";
import path from "node:path";
import webpack from "webpack";
import CopyWebpackPlugin from "copy-webpack-plugin";
import MikelWebpackPlugin from "mikel-webpack-plugin";
import {getChangelogData} from "./scripts/changelog.js";
import {getPages} from "./scripts/pages.js";
import env from "./server/utils/environment.js";
// read package.json
const pkg = JSON.parse(fs.readFileSync("./package.json"));
// available clients for folio
const CLIENTS = {
LOCAL: path.join(process.cwd(), "app/clients/local.js"),
REMOTE: path.join(process.cwd(), "app/clients/remote.js"),
};
// @description global data configuration
// @field site: site configuration
// @field page: current page configuration
const globalData = {
site: {
title: "Folio",
repository: pkg.repository,
version: pkg.version,
navbar: {
links: [
{link: "/#features", text: "Features"},
{link: "/#pricing", text: "Pricing"},
{link: "/changelog", text: "Changelog"},
],
},
footer: {
links: [
{link: "/privacy", target: "_self", text: "Privacy"},
{link: "https://github.com/jmjuanes/folio/issues", target: "_blank", text: "Report a bug"},
],
},
},
pages: getPages(path.join(process.cwd(), "pages"), ".html"),
page: null,
data: {
changelog: getChangelogData(path.join(process.cwd(), "CHANGELOG.md")),
},
};
export default {
mode: process.env.NODE_ENV || "development", // "production",
target: "web",
entry: path.join(process.cwd(), "app", "index.jsx"),
output: {
path: path.join(process.cwd(), "www"),
publicPath: "./",
filename: "[name].[contenthash].js",
chunkFilename: "[name].[contenthash].chunk.js",
assetModuleFilename: "assets/[hash][ext][query]",
},
resolve:{
alias: {
"@folio/client": CLIENTS[(env?.CLIENT || "LOCAL").toUpperCase()],
},
},
optimization: {
splitChunks: {
chunks: "all",
},
},
devServer: {
hot: false,
static: {
directory: path.join(process.cwd(), "www"),
staticOptions: {
extensions: ["html"],
},
},
historyApiFallback: {
rewrites: [
{from: /^\/$/, to: "app.html"},
{from: /^\/index.html$/, to: "app.html"},
],
},
devMiddleware: {
writeToDisk: true,
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: [
path.join(process.cwd(), "app"),
path.join(process.cwd(), "pkgs"),
],
exclude: /(node_modules|www)/,
loader: "babel-loader",
options: {
presets: [
"@babel/preset-react",
],
},
},
{
test: /\.(png|jpg|jpeg|svg)$/,
type: "asset/resource",
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
},
{
test: /resources\/stickers\/([\w-]+)\.svg$/,
type: "asset/inline",
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
// Global values
"process.env.VERSION": JSON.stringify(pkg.version),
"process.env.URL_REPOSITORY": JSON.stringify(pkg.repository),
"process.env.URL_ISSUES": JSON.stringify(pkg.bugs),
"process.env.URL_HOMEPAGE": JSON.stringify(pkg.homepage),
// ENV values
"process.env.APP": JSON.stringify(env.APP || "LITE"),
"process.env.CLIENT": JSON.stringify(env.CLIENT || "LOCAL"),
}),
new CopyWebpackPlugin({
patterns: [
path.join(process.cwd(), "node_modules/lowcss/low.css"),
path.join(process.cwd(), "node_modules/@josemi-icons/svg/sprite.svg"),
],
}),
// new HtmlWebpackPlugin({
// template: path.join(process.cwd(), "app", "template.html"),
// filename: "app.html",
// minify: true,
// }),
...globalData.pages.map(page => {
return new MikelWebpackPlugin({
template: path.join(process.cwd(), "layout.html"),
filename: page.url,
chunks: page.data.chunks || [],
templateData: Object.assign({}, globalData, {
page: page,
}),
templateOptions: {
partials: {
content: page.content,
},
functions: {
icon: ({opt}) => {
return `<svg class="size-${opt.size || "4"}"><use xlink:href="sprite.svg#${opt.icon}"></use></svg>`;
},
},
},
});
}),
],
};