Skip to content

Commit 1feee35

Browse files
authored
Configure package exports explicitly (#336)
Closes #337 Blocks webrecorder/archiveweb.page#198 Adds a dedicated `misc` export, as well as explicitly exporting the `electron-*` files and the `index.html` file. This restricts imports to only these files, and allows us to not have to exactly match webpack configs between RWP and AWP.
1 parent 2700797 commit 1feee35

File tree

4 files changed

+102
-5
lines changed

4 files changed

+102
-5
lines changed

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
"homepage": "https://replayweb.page/",
88
"author": "Webrecorder Software",
99
"license": "AGPL-3.0-or-later",
10-
"main": "ui.js",
11-
"types": "dist/types/index.d.ts",
10+
"exports": {
11+
".": {
12+
"types": "./dist/types/index.d.ts",
13+
"default": "./ui.js"
14+
},
15+
"./misc": {
16+
"types": "./dist/types/misc.d.ts",
17+
"default": "./dist/misc.js"
18+
},
19+
"./src/electron-*": "./src/electron-*.ts",
20+
"./index.html": "./index.html"
21+
},
1222
"dependencies": {
1323
"@fortawesome/fontawesome-free": "^5.15.4",
1424
"@shoelace-style/shoelace": "~2.15.1",

src/components/labeled-field.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import faX from "@fortawesome/fontawesome-free/svgs/solid/times.svg";
88

99
import { registerIconLibrary } from "@shoelace-style/shoelace/dist/utilities/icon-library.js";
1010

11-
import systemLibrary from "@shoelace-style/shoelace/dist/components/icon/library.system";
11+
import systemLibrary from "@shoelace-style/shoelace/dist/components/icon/library.system.js";
1212

1313
// disable system library to prevent loading of unused data: URLs
1414
// allow only "x-lg" as it is needed for sl-dialog

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"outDir": "./dist/",
44
"module": "esnext",
55
"target": "es6",
6-
"moduleResolution": "node",
6+
"moduleResolution": "Bundler",
77
"allowJs": true,
88
"strict": true,
99
"declaration": true,

webpack.config.js

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,91 @@ const browserConfig = (/*env, argv*/) => {
188188
return merge(tsConfig, config);
189189
};
190190

191-
module.exports = [browserConfig, electronMainConfig, electronPreloadConfig];
191+
const miscConfig = (/*env, argv*/) => {
192+
const isDevServer = process.env.WEBPACK_SERVE;
193+
194+
/** @type {import('webpack').Configuration['entry']} */
195+
const entry = {
196+
misc: "./src/misc.ts",
197+
};
198+
199+
/** @type {import('webpack').Configuration} */
200+
const config = {
201+
target: "web",
202+
mode: "production",
203+
cache: {
204+
type: isDevServer ? "memory" : "filesystem",
205+
},
206+
resolve: {
207+
fallback: { crypto: false },
208+
},
209+
entry,
210+
optimization,
211+
212+
output: {
213+
path: path.join(__dirname, "dist"),
214+
filename: "[name].js",
215+
libraryTarget: "self",
216+
globalObject: "self",
217+
publicPath: "/",
218+
},
219+
220+
devServer: {
221+
compress: true,
222+
port: 9990,
223+
open: false,
224+
static: __dirname,
225+
//publicPath: "/"
226+
},
227+
228+
plugins: [
229+
new webpack.NormalModuleReplacementPlugin(/^node:*/, (resource) => {
230+
switch (resource.request) {
231+
case "node:stream":
232+
resource.request = "stream-browserify";
233+
break;
234+
}
235+
}),
236+
237+
new webpack.optimize.LimitChunkCountPlugin({
238+
maxChunks: 1,
239+
}),
240+
new webpack.ProvidePlugin({
241+
process: "process/browser",
242+
}),
243+
new MiniCssExtractPlugin(),
244+
new webpack.DefinePlugin({
245+
__SW_NAME__: JSON.stringify("sw.js"),
246+
__HELPER_PROXY__: JSON.stringify(HELPER_PROXY),
247+
__GDRIVE_CLIENT_ID__: JSON.stringify(GDRIVE_CLIENT_ID),
248+
__VERSION__: JSON.stringify(package_json.version),
249+
}),
250+
new webpack.BannerPlugin(BANNER_TEXT),
251+
],
252+
253+
module: {
254+
rules: [
255+
{
256+
test: /\.svg$/,
257+
use: ["raw-loader"],
258+
},
259+
{
260+
test: /main.scss$/,
261+
use: ["css-loader", "sass-loader"],
262+
},
263+
{
264+
test: /wombat.js|wombatWorkers.js|index.html$/i,
265+
use: ["raw-loader"],
266+
},
267+
],
268+
},
269+
};
270+
return merge(tsConfig, config);
271+
};
272+
273+
module.exports = [
274+
browserConfig,
275+
miscConfig,
276+
electronMainConfig,
277+
electronPreloadConfig,
278+
];

0 commit comments

Comments
 (0)