mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move webpack cache to data root
This commit is contained in:
@ -1,35 +1,59 @@
|
||||
import process from 'node:process';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import isDocker from 'is-docker';
|
||||
|
||||
/** @type {import('webpack').Configuration} */
|
||||
export const publicLibConfig = {
|
||||
mode: 'production',
|
||||
entry: './public/lib.js',
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
cacheDirectory: path.resolve(process.cwd(), 'dist/webpack'),
|
||||
store: 'pack',
|
||||
compression: 'gzip',
|
||||
},
|
||||
devtool: false,
|
||||
watch: false,
|
||||
module: {},
|
||||
stats: {
|
||||
preset: 'minimal',
|
||||
assets: false,
|
||||
modules: false,
|
||||
colors: true,
|
||||
timings: true,
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true,
|
||||
},
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(process.cwd(), 'dist'),
|
||||
filename: 'lib.js',
|
||||
libraryTarget: 'module',
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Get the Webpack configuration for the public/lib.js file.
|
||||
* @param {boolean} forceDist Whether to force the use the /dist folder.
|
||||
* @returns {import('webpack').Configuration}
|
||||
* */
|
||||
export default function getPublicLibConfig(forceDist = false) {
|
||||
function getCacheDirectory() {
|
||||
// Docker got cache pre-baked into the image.
|
||||
if (forceDist || isDocker()) {
|
||||
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') {
|
||||
return path.resolve(globalThis.DATA_ROOT, '_cache', 'webpack');
|
||||
}
|
||||
|
||||
// Fallback to the system temp directory.
|
||||
return path.resolve(os.tmpdir(), 'webpack');
|
||||
}
|
||||
|
||||
const cacheDirectory = getCacheDirectory();
|
||||
return {
|
||||
mode: 'production',
|
||||
entry: './public/lib.js',
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
cacheDirectory: cacheDirectory,
|
||||
store: 'pack',
|
||||
compression: 'gzip',
|
||||
},
|
||||
devtool: false,
|
||||
watch: false,
|
||||
module: {},
|
||||
stats: {
|
||||
preset: 'minimal',
|
||||
assets: false,
|
||||
modules: false,
|
||||
colors: true,
|
||||
timings: true,
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true,
|
||||
},
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(process.cwd(), 'dist'),
|
||||
filename: 'lib.js',
|
||||
libraryTarget: 'module',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user