mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-13 02:20:14 +01:00
Set lib.js output path to data
This commit is contained in:
parent
441e5c6f7e
commit
0f46128980
@ -1,30 +1,43 @@
|
|||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
|
||||||
import isDocker from 'is-docker';
|
import isDocker from 'is-docker';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Webpack configuration for the public/lib.js file.
|
* Get the Webpack configuration for the public/lib.js file.
|
||||||
|
* 1. Docker has got cache and the output file pre-baked.
|
||||||
|
* 2. Non-Docker environments use the global DATA_ROOT variable to determine the cache and output directories.
|
||||||
* @param {boolean} forceDist Whether to force the use the /dist folder.
|
* @param {boolean} forceDist Whether to force the use the /dist folder.
|
||||||
* @returns {import('webpack').Configuration}
|
* @returns {import('webpack').Configuration}
|
||||||
|
* @throws {Error} If the DATA_ROOT variable is not set.
|
||||||
* */
|
* */
|
||||||
export default function getPublicLibConfig(forceDist = false) {
|
export default function getPublicLibConfig(forceDist = false) {
|
||||||
function getCacheDirectory() {
|
function getCacheDirectory() {
|
||||||
// Docker got cache pre-baked into the image.
|
|
||||||
if (forceDist || isDocker()) {
|
if (forceDist || isDocker()) {
|
||||||
return path.resolve(process.cwd(), 'dist/webpack');
|
return path.resolve(process.cwd(), 'dist/webpack');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data root is set (should be the case 99.99% of the time).
|
|
||||||
if (typeof globalThis.DATA_ROOT === 'string') {
|
if (typeof globalThis.DATA_ROOT === 'string') {
|
||||||
return path.resolve(globalThis.DATA_ROOT, '_cache', 'webpack');
|
return path.resolve(globalThis.DATA_ROOT, '_webpack', 'cache');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to the system temp directory.
|
throw new Error('DATA_ROOT variable is not set.');
|
||||||
return path.resolve(os.tmpdir(), 'webpack');
|
}
|
||||||
|
|
||||||
|
function getOutputDirectory() {
|
||||||
|
if (forceDist || isDocker()) {
|
||||||
|
return path.resolve(process.cwd(), 'dist');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof globalThis.DATA_ROOT === 'string') {
|
||||||
|
return path.resolve(globalThis.DATA_ROOT, '_webpack', 'output');
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error('DATA_ROOT variable is not set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const cacheDirectory = getCacheDirectory();
|
const cacheDirectory = getCacheDirectory();
|
||||||
|
const outputDirectory = getOutputDirectory();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
entry: './public/lib.js',
|
entry: './public/lib.js',
|
||||||
@ -51,7 +64,7 @@ export default function getPublicLibConfig(forceDist = false) {
|
|||||||
hints: false,
|
hints: false,
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(process.cwd(), 'dist'),
|
path: outputDirectory,
|
||||||
filename: 'lib.js',
|
filename: 'lib.js',
|
||||||
libraryTarget: 'module',
|
libraryTarget: 'module',
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user