Set lib.js output path to data

0f461289800642d6262bbb06cb1a86007d11bb94

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +20 -7Ignore whitespace
webpack.config.js+20 -7
@@ -1,30 +1,43 @@
11import process from 'node:process';
22import path from 'node:path';
3-import os from 'node:os';
43import isDocker from 'is-docker';
54
65/**
76 * Get the Webpack configuration for the public/lib.js file.
7+ * 1. Docker has got cache and the output file pre-baked.
8+ * 2. Non-Docker environments use the global DATA_ROOT variable to determine the cache and output directories.
89 * @param {boolean} forceDist Whether to force the use the /dist folder.
910 * @returns {import('webpack').Configuration}
11+ * @throws {Error} If the DATA_ROOT variable is not set.
1012 * */
1113export default function getPublicLibConfig(forceDist = false) {
1214 function getCacheDirectory() {
13- // Docker got cache pre-baked into the image.
1415 if (forceDist || isDocker()) {
1516 return path.resolve(process.cwd(), 'dist/webpack');
1617 }
1718
18- // Data root is set (should be the case 99.99% of the time).
1919 if (typeof globalThis.DATA_ROOT === 'string') {
2020 return path.resolve(globalThis.DATA_ROOT, '_cache_webpack', 'webpackcache');
2121 }
2222
23- // Fallback to the system temp directory.
23+ throw new Error('DATA_ROOT variable is not set.');
24- return path.resolve(os.tmpdir(), 'webpack');
24+ }
25+
26+ function getOutputDirectory() {
27+ if (forceDist || isDocker()) {
28+ return path.resolve(process.cwd(), 'dist');
29+ }
30+
31+ if (typeof globalThis.DATA_ROOT === 'string') {
32+ return path.resolve(globalThis.DATA_ROOT, '_webpack', 'output');
33+ }
34+
35+ throw new Error('DATA_ROOT variable is not set.');
2536 }
2637
2738 const cacheDirectory = getCacheDirectory();
39+ const outputDirectory = getOutputDirectory();
40+
2841 return {
2942 mode: 'production',
3043 entry: './public/lib.js',
@@ -51,7 +64,7 @@ export default function getPublicLibConfig(forceDist = false) {
5164 hints: false,
5265 },
5366 output: {
54- path: path.resolve(process.cwd(), 'dist'),
67+ path: outputDirectory,
5568 filename: 'lib.js',
5669 libraryTarget: 'module',
5770 },