-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrspack.config.js
More file actions
146 lines (144 loc) · 4.04 KB
/
rspack.config.js
File metadata and controls
146 lines (144 loc) · 4.04 KB
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
const fs = require('fs');
const path = require('path');
const { rspack } = require('@rspack/core');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
// We need to generate a list of locales that Shoelace supports for out localization logic
const shoelaceLocalesDirectory = path.resolve(__dirname, "./node_modules/@shoelace-style/shoelace/dist/translations");
const shoelaceLocales = [];
fs.readdirSync(shoelaceLocalesDirectory).forEach(file => {
if (file.endsWith('.js')) {
const locale = file.split('.')[0];
shoelaceLocales.push(locale);
}
});
module.exports = (env, argv) => {
let devtool = false;
if (argv.mode && argv.mode === 'development') {
devtool = 'eval';
}
/** @type {import('@rspack/cli').Configuration} */
const config = {
mode: argv.mode,
entry: {
extension: [path.resolve(__dirname, "./src/overlay/index.ts")],
config: [path.resolve(__dirname, "./src/config/index.ts")]
},
output: {
path: path.resolve(__dirname, "./dist"),
filename: "[name].[contenthash].bundle.js",
publicPath: "",
assetModuleFilename: "assets/[name].[contenthash].[ext]"
},
optimization: {
minimize: devtool ? true : false,
},
module: {
rules: [
// Loading TypeScript
{
test: /\.ts?$/,
type: 'javascript/auto',
use: [
{
loader: 'minify-html-literals-loader'
},
{
loader: 'builtin:swc-loader',
/** @type {import('@rspack/core').SwcLoaderOptions} */
options: {
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
},
transform: {
legacyDecorator: true,
useDefineForClassFields: false
},
},
}
}
],
exclude: /node_modules/,
},
// Used for loading scss files
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: "lit-css-loader",
},
{
loader: "sass-loader",
options: {
sassOptions: {
outputStyle: "compressed",
api: 'modern-compiler',
implementation: require.resolve('sass-embedded')
},
},
},
],
},
// Loading images
{
test: /\.(png|svg|jpg|gif|ico|webp)$/,
type: 'asset/resource',
}
],
},
resolve: {
extensions: [".ts", ".js"],
},
devServer: {
port: 8083,
host: "localhost",
hot: true,
open: env.page ? [`/${env.page}`] : ['/'],
compress: true,
devMiddleware: {
index: "index.html",
},
},
plugins: [
new CleanWebpackPlugin(),
new rspack.DefinePlugin({
VERSION: JSON.stringify(process.env.npm_package_version),
SHOELACE_LOCALES: JSON.stringify(shoelaceLocales)
}),
new rspack.HtmlRspackPlugin({
template: "./src/overlay/index.html",
filename: "index.html",
hash: true,
inject: "head",
chunks: ["extension"],
}),
new rspack.HtmlRspackPlugin({
template: "./src/config/index.html",
filename: "config.html",
hash: true,
inject: "head",
chunks: ["config"],
}),
new rspack.CopyRspackPlugin({
patterns: [
// Used to ensure Webcomponent compatibility for older browsers
{
context: "node_modules/@webcomponents/webcomponentsjs",
from: "webcomponents-loader.js",
to: "webcomponents",
},
// Copy theme css for Shoelace
{
context: 'node_modules/@shoelace-style/shoelace/dist/themes',
from: '*.css',
to: 'shoelace/themes',
}
],
}),
],
devtool,
};
return config;
};