Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
106 lines (95 loc) · 3.57 KB
/
Copy pathwebpack.config.js
File metadata and controls
106 lines (95 loc) · 3.57 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
/********************************************************************************
* Copyright (C) 2026 CoCreate and Contributors.
*
* Licensed under GNU AGPLv3.
********************************************************************************/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import webpack from "webpack";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const workspaceRoot = path.resolve(__dirname, "..");
function workspaceAliases() {
const aliases = {};
for (const directory of [
"CoCreate-modules",
"CoCreate-plugins"
]) {
const packagesDirectory = path.join(workspaceRoot, directory);
if (!fs.existsSync(packagesDirectory)) continue;
for (const packageDirectory of fs.readdirSync(packagesDirectory)) {
const absoluteDirectory = path.join(packagesDirectory, packageDirectory);
const packagePath = path.join(absoluteDirectory, "package.json");
if (!fs.existsSync(packagePath)) continue;
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
if (packageJson.name?.startsWith("@cocreate/")) {
aliases[packageJson.name] = absoluteDirectory;
}
}
}
// Only the lightweight AI configuration shell belongs in the server
// bundle. It resolves the disk-based runtime when AI is enabled.
aliases["@cocreate/ai"] = path.join(
__dirname,
"plugins/ai/bootstrap.js"
);
return aliases;
}
class RuntimeAssetsPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tap("RuntimeAssetsPlugin", () => {
const pluginSource = path.join(__dirname, "plugins");
const pluginOutput = path.join(compiler.options.output.path, "plugins");
if (!fs.existsSync(path.join(pluginSource, "ai", "index.js")) ||
!fs.existsSync(path.join(pluginSource, "ai", "runtime.js"))) {
throw new Error(`Missing plugin distributions: ${pluginSource}`);
}
fs.cpSync(pluginSource, pluginOutput, { recursive: true });
fs.writeFileSync(
path.join(compiler.options.output.path, "package.json"),
`${JSON.stringify({ private: true, type: "module" }, null, 2)}\n`
);
const storagePackages = path.join(__dirname, "storages");
const storageOutput = path.join(compiler.options.output.path, "storages");
fs.mkdirSync(storageOutput, { recursive: true });
if (!fs.existsSync(storagePackages)) {
throw new Error(`Missing built storage distributions: ${storagePackages}`);
}
fs.cpSync(storagePackages, storageOutput, { recursive: true });
});
}
}
export default {
mode: "production",
target: "node18",
entry: "./src/index.js",
experiments: {
outputModule: true
},
resolve: {
alias: workspaceAliases(),
extensions: [".js", ".mjs", ".cjs", ".json"],
fullySpecified: false
},
output: {
path: path.resolve(__dirname, "dist/node"),
filename: "index.js",
library: { type: "module" },
clean: true,
globalObject: "this"
},
optimization: {
minimize: false,
concatenateModules: false,
splitChunks: false,
runtimeChunk: false
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new RuntimeAssetsPlugin()
],
performance: {
hints: false
},
devtool: false
};