-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.cjs
151 lines (144 loc) · 4.65 KB
/
webpack.config.cjs
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
const path = require("path");
const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const BANNER = `[name].js is part of the Webrecorder Create Archive Now! (CAN!) (https://create.webrecorder.net/) Copyright (C) 2024-${new Date().getFullYear()}, Webrecorder Software. Licensed under the Affero General Public License v3.`;
/** @type {import('webpack').Configuration} */
module.exports = (env, argv) => {
return {
mode: env.production ? "production" : "development",
entry: {
main: "src/index.ts",
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js",
clean: true,
},
resolve: {
extensions: [".ts", ".js"],
plugins: [
new TsconfigPathsPlugin(),
],
},
//devtool: argv.mode === "production" ? undefined : "source-map",
devServer: {
compress: true,
port: 10001,
open: "/#url=https://example.com/",
static: path.join(__dirname, "dist"),
hot: true,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
module: {
rules: [
{
test: /\.tsx?$/,
include: path.resolve(__dirname, "src"),
use: [
{
loader: "postcss-loader",
options: {
postcssOptions: {
syntax: "postcss-lit",
plugins: ["tailwindcss", "autoprefixer"],
},
},
},
{
loader: "ts-loader",
options: {
onlyCompileBundledFiles: true,
transpileOnly: true,
},
},
],
},
{
// Global styles and assets, like fonts and Shoelace,
// that get added to document styles
test: /\.css$/i,
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "node_modules/@shoelace-style/shoelace"),
],
exclude: /\.stylesheet\.css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader",
],
},
{
// CSS loaded as raw string and used as a CSSStyleSheet
test: /\.stylesheet\.css$/,
type: "asset/source",
include: [path.resolve(__dirname, "src")],
use: ["postcss-loader"],
},
{
test: /\.(png|svg|jpg|jpeg|gif|avif)$/i,
type: "asset/resource",
},
],
},
plugins: [
// doing this separately for now
//new CopyPlugin({
// patterns: [
// { from: "./node_modules/\@webrecorder/archivewebpage/dist/embed/ui.js", to: "../awp-ui.js" },
// { from: "./node_modules/\@webrecorder/archivewebpage/dist/embed/replay/sw.js", to: "../replay/sw.js" }
// ],
//}),
new webpack.BannerPlugin(BANNER),
new ForkTsCheckerWebpackPlugin({}),
new MiniCssExtractPlugin(),
new CopyPlugin({
patterns: [
// Copy Shoelace assets to dist/shoelace
{
from: path.resolve(
__dirname,
"node_modules/@shoelace-style/shoelace/dist/assets",
),
to: path.resolve(__dirname, "dist/shoelace/assets"),
},
{
from: "./node_modules/@webrecorder/archivewebpage/dist/embed/ui.js",
to: path.resolve(__dirname, "dist/awp-ui.js"),
},
{
from: "./node_modules/@webrecorder/archivewebpage/dist/embed/replay/sw.js",
to: path.resolve(__dirname, "dist/replay/sw.js"),
},
],
}),
new HtmlWebpackPlugin({
template: "src/index.ejs",
templateParameters: {
production: env.production,
title: "Create Archive Now • Webrecorder",
description:
"Create Archive Now, a demo of Webrecorder’s web archiving tools",
baseUrl: "https://create.webrecorder.net",
homeUrl: "https://create.webrecorder.net",
// optional landing site url if no hashtag provided
landingSiteUrl: process.env.LANDING_SITE_URL,
},
inject: "head",
scriptLoading: "blocking",
}),
],
};
};