@hato810424/mc-resources-plugin 0.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/package.json +43 -0
- package/packages/mc-resources-plugin/dist/core-BHoK8fPV.mjs +2300 -0
- package/packages/mc-resources-plugin/dist/core-BP2mwKSk.cjs +2333 -0
- package/packages/mc-resources-plugin/dist/docusaurus.cjs +54 -0
- package/packages/mc-resources-plugin/dist/docusaurus.d.cts +6 -0
- package/packages/mc-resources-plugin/dist/docusaurus.d.mts +7 -0
- package/packages/mc-resources-plugin/dist/docusaurus.mjs +54 -0
- package/packages/mc-resources-plugin/dist/types-BEv9afFy.d.mts +21 -0
- package/packages/mc-resources-plugin/dist/types-BGQHsCJS.d.cts +21 -0
- package/packages/mc-resources-plugin/dist/vite.cjs +56 -0
- package/packages/mc-resources-plugin/dist/vite.d.cts +12 -0
- package/packages/mc-resources-plugin/dist/vite.d.mts +13 -0
- package/packages/mc-resources-plugin/dist/vite.mjs +56 -0
- package/packages/mc-resources-plugin/dist/webpack.cjs +83 -0
- package/packages/mc-resources-plugin/dist/webpack.d.cts +15 -0
- package/packages/mc-resources-plugin/dist/webpack.d.mts +16 -0
- package/packages/mc-resources-plugin/dist/webpack.mjs +83 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const require_core = require('./core-BP2mwKSk.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/docusaurus.ts
|
|
4
|
+
function docusaurusPlugin(pluginOptions) {
|
|
5
|
+
return async function pluginInstance(context) {
|
|
6
|
+
const core = new require_core.McResourcesCore(pluginOptions);
|
|
7
|
+
let isGenerated = false;
|
|
8
|
+
const isBuild = process.env.NODE_ENV === "production" || context.siteConfig.customFields?.buildMode === true;
|
|
9
|
+
if (isBuild) {
|
|
10
|
+
await core.getAssetsInBuildMode();
|
|
11
|
+
await core.build({ distDir: context.outDir });
|
|
12
|
+
} else core.getAssetsInDevMode();
|
|
13
|
+
return {
|
|
14
|
+
name: "@hato810424/mc-resources-plugin-docusaurus",
|
|
15
|
+
async loadContent() {},
|
|
16
|
+
configureWebpack(config, isServer, utils) {
|
|
17
|
+
if (isServer) return {};
|
|
18
|
+
if (!config.devServer) config.devServer = {};
|
|
19
|
+
const originalSetupMiddlewares = config.devServer.setupMiddlewares;
|
|
20
|
+
return { devServer: { setupMiddlewares: (middlewares, devServer) => {
|
|
21
|
+
if (!devServer.app) throw new Error("webpack-dev-server app is not defined");
|
|
22
|
+
if (originalSetupMiddlewares) middlewares = originalSetupMiddlewares(middlewares, devServer);
|
|
23
|
+
if (!isBuild) core.devServerStart();
|
|
24
|
+
devServer.app.get("/@hato810424:mc-resources-plugin/*", (req, res, next) => {
|
|
25
|
+
core.devServerMiddleware({
|
|
26
|
+
next,
|
|
27
|
+
req: {
|
|
28
|
+
url: req.url,
|
|
29
|
+
headers: req.headers
|
|
30
|
+
},
|
|
31
|
+
res: {
|
|
32
|
+
setStatus: (statusCode) => {
|
|
33
|
+
res.statusCode = statusCode;
|
|
34
|
+
},
|
|
35
|
+
setHeader: (name, value) => {
|
|
36
|
+
res.setHeader(name, value);
|
|
37
|
+
},
|
|
38
|
+
send: (body) => {
|
|
39
|
+
res.end(body);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
isBuild,
|
|
43
|
+
isGenerated
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return middlewares;
|
|
47
|
+
} } };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
module.exports = docusaurusPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { t as PluginOptions } from "./types-BEv9afFy.mjs";
|
|
2
|
+
import { PluginModule } from "@docusaurus/types";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/docusaurus.d.ts
|
|
5
|
+
declare function docusaurusPlugin(pluginOptions: PluginOptions): PluginModule<void>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { docusaurusPlugin as default };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { t as McResourcesCore } from "./core-BHoK8fPV.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/docusaurus.ts
|
|
4
|
+
function docusaurusPlugin(pluginOptions) {
|
|
5
|
+
return async function pluginInstance(context) {
|
|
6
|
+
const core = new McResourcesCore(pluginOptions);
|
|
7
|
+
let isGenerated = false;
|
|
8
|
+
const isBuild = process.env.NODE_ENV === "production" || context.siteConfig.customFields?.buildMode === true;
|
|
9
|
+
if (isBuild) {
|
|
10
|
+
await core.getAssetsInBuildMode();
|
|
11
|
+
await core.build({ distDir: context.outDir });
|
|
12
|
+
} else core.getAssetsInDevMode();
|
|
13
|
+
return {
|
|
14
|
+
name: "@hato810424/mc-resources-plugin-docusaurus",
|
|
15
|
+
async loadContent() {},
|
|
16
|
+
configureWebpack(config, isServer, utils) {
|
|
17
|
+
if (isServer) return {};
|
|
18
|
+
if (!config.devServer) config.devServer = {};
|
|
19
|
+
const originalSetupMiddlewares = config.devServer.setupMiddlewares;
|
|
20
|
+
return { devServer: { setupMiddlewares: (middlewares, devServer) => {
|
|
21
|
+
if (!devServer.app) throw new Error("webpack-dev-server app is not defined");
|
|
22
|
+
if (originalSetupMiddlewares) middlewares = originalSetupMiddlewares(middlewares, devServer);
|
|
23
|
+
if (!isBuild) core.devServerStart();
|
|
24
|
+
devServer.app.get("/@hato810424:mc-resources-plugin/*", (req, res, next) => {
|
|
25
|
+
core.devServerMiddleware({
|
|
26
|
+
next,
|
|
27
|
+
req: {
|
|
28
|
+
url: req.url,
|
|
29
|
+
headers: req.headers
|
|
30
|
+
},
|
|
31
|
+
res: {
|
|
32
|
+
setStatus: (statusCode) => {
|
|
33
|
+
res.statusCode = statusCode;
|
|
34
|
+
},
|
|
35
|
+
setHeader: (name, value) => {
|
|
36
|
+
res.setHeader(name, value);
|
|
37
|
+
},
|
|
38
|
+
send: (body) => {
|
|
39
|
+
res.end(body);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
isBuild,
|
|
43
|
+
isGenerated
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return middlewares;
|
|
47
|
+
} } };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { docusaurusPlugin as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare const PluginOptionsSchema: z.ZodObject<{
|
|
5
|
+
mcVersion: z.ZodString;
|
|
6
|
+
resourcePackPath: z.ZodString;
|
|
7
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
8
|
+
emptyOutDir: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
+
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
10
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
cacheDir: z.ZodOptional<z.ZodString>;
|
|
12
|
+
startUpRenderCacheRefresh: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
logLevel: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
error: "error";
|
|
15
|
+
info: "info";
|
|
16
|
+
debug: "debug";
|
|
17
|
+
}>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
type PluginOptions = z.infer<typeof PluginOptionsSchema>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { PluginOptions as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare const PluginOptionsSchema: z.ZodObject<{
|
|
5
|
+
mcVersion: z.ZodString;
|
|
6
|
+
resourcePackPath: z.ZodString;
|
|
7
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
8
|
+
emptyOutDir: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
+
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
10
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
cacheDir: z.ZodOptional<z.ZodString>;
|
|
12
|
+
startUpRenderCacheRefresh: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
logLevel: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
error: "error";
|
|
15
|
+
info: "info";
|
|
16
|
+
debug: "debug";
|
|
17
|
+
}>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
type PluginOptions = z.infer<typeof PluginOptionsSchema>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { PluginOptions as t };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const require_core = require('./core-BP2mwKSk.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/vite.ts
|
|
4
|
+
const mcResourcesPlugin = async (options) => {
|
|
5
|
+
let isGenerated = false;
|
|
6
|
+
const core = new require_core.McResourcesCore(options);
|
|
7
|
+
let isBuild = false;
|
|
8
|
+
let isPreview = false;
|
|
9
|
+
let outDir;
|
|
10
|
+
let configResolvedDone = false;
|
|
11
|
+
return {
|
|
12
|
+
name: "@hato810424/mc-resources-plugin",
|
|
13
|
+
configResolved: async (config) => {
|
|
14
|
+
if (configResolvedDone) return;
|
|
15
|
+
configResolvedDone = true;
|
|
16
|
+
if (config.command === "build") isBuild = true;
|
|
17
|
+
if (config.isProduction && config.command === "serve") isPreview = true;
|
|
18
|
+
if (!isBuild && !isPreview) core.getAssetsInDevMode();
|
|
19
|
+
else await core.getAssetsInBuildMode();
|
|
20
|
+
outDir = config.build.outDir;
|
|
21
|
+
},
|
|
22
|
+
buildStart: async function() {
|
|
23
|
+
if (isPreview) return;
|
|
24
|
+
if (isBuild) await core.build({ distDir: outDir });
|
|
25
|
+
},
|
|
26
|
+
configureServer: (server) => {
|
|
27
|
+
if (!isBuild && !isPreview) core.devServerStart();
|
|
28
|
+
server.middlewares.use(async (req, res, next) => {
|
|
29
|
+
return await core.devServerMiddleware({
|
|
30
|
+
next,
|
|
31
|
+
req: {
|
|
32
|
+
url: req.url,
|
|
33
|
+
headers: req.headers
|
|
34
|
+
},
|
|
35
|
+
res: {
|
|
36
|
+
setStatus: (statusCode) => {
|
|
37
|
+
res.statusCode = statusCode;
|
|
38
|
+
},
|
|
39
|
+
setHeader: (name, value) => {
|
|
40
|
+
res.setHeader(name, value);
|
|
41
|
+
},
|
|
42
|
+
send: (body) => {
|
|
43
|
+
res.end(body);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
isBuild,
|
|
47
|
+
isGenerated
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var vite_default = mcResourcesPlugin;
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
module.exports = vite_default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as PluginOptions } from "./types-BGQHsCJS.cjs";
|
|
2
|
+
import * as vite0 from "vite";
|
|
3
|
+
import * as rollup0 from "rollup";
|
|
4
|
+
|
|
5
|
+
//#region src/plugin/vite.d.ts
|
|
6
|
+
declare const mcResourcesPlugin: (options: PluginOptions) => Promise<{
|
|
7
|
+
name: string;
|
|
8
|
+
configResolved: (this: vite0.MinimalPluginContextWithoutEnvironment, config: vite0.ResolvedConfig) => Promise<void>;
|
|
9
|
+
buildStart: (this: rollup0.PluginContext) => Promise<void>;
|
|
10
|
+
configureServer: (this: vite0.MinimalPluginContextWithoutEnvironment, server: vite0.ViteDevServer) => void;
|
|
11
|
+
}>;
|
|
12
|
+
export = mcResourcesPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as PluginOptions } from "./types-BEv9afFy.mjs";
|
|
2
|
+
import * as vite0 from "vite";
|
|
3
|
+
import * as rollup0 from "rollup";
|
|
4
|
+
|
|
5
|
+
//#region src/plugin/vite.d.ts
|
|
6
|
+
declare const mcResourcesPlugin: (options: PluginOptions) => Promise<{
|
|
7
|
+
name: string;
|
|
8
|
+
configResolved: (this: vite0.MinimalPluginContextWithoutEnvironment, config: vite0.ResolvedConfig) => Promise<void>;
|
|
9
|
+
buildStart: (this: rollup0.PluginContext) => Promise<void>;
|
|
10
|
+
configureServer: (this: vite0.MinimalPluginContextWithoutEnvironment, server: vite0.ViteDevServer) => void;
|
|
11
|
+
}>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { mcResourcesPlugin as default };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { t as McResourcesCore } from "./core-BHoK8fPV.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/vite.ts
|
|
4
|
+
const mcResourcesPlugin = async (options) => {
|
|
5
|
+
let isGenerated = false;
|
|
6
|
+
const core = new McResourcesCore(options);
|
|
7
|
+
let isBuild = false;
|
|
8
|
+
let isPreview = false;
|
|
9
|
+
let outDir;
|
|
10
|
+
let configResolvedDone = false;
|
|
11
|
+
return {
|
|
12
|
+
name: "@hato810424/mc-resources-plugin",
|
|
13
|
+
configResolved: async (config) => {
|
|
14
|
+
if (configResolvedDone) return;
|
|
15
|
+
configResolvedDone = true;
|
|
16
|
+
if (config.command === "build") isBuild = true;
|
|
17
|
+
if (config.isProduction && config.command === "serve") isPreview = true;
|
|
18
|
+
if (!isBuild && !isPreview) core.getAssetsInDevMode();
|
|
19
|
+
else await core.getAssetsInBuildMode();
|
|
20
|
+
outDir = config.build.outDir;
|
|
21
|
+
},
|
|
22
|
+
buildStart: async function() {
|
|
23
|
+
if (isPreview) return;
|
|
24
|
+
if (isBuild) await core.build({ distDir: outDir });
|
|
25
|
+
},
|
|
26
|
+
configureServer: (server) => {
|
|
27
|
+
if (!isBuild && !isPreview) core.devServerStart();
|
|
28
|
+
server.middlewares.use(async (req, res, next) => {
|
|
29
|
+
return await core.devServerMiddleware({
|
|
30
|
+
next,
|
|
31
|
+
req: {
|
|
32
|
+
url: req.url,
|
|
33
|
+
headers: req.headers
|
|
34
|
+
},
|
|
35
|
+
res: {
|
|
36
|
+
setStatus: (statusCode) => {
|
|
37
|
+
res.statusCode = statusCode;
|
|
38
|
+
},
|
|
39
|
+
setHeader: (name, value) => {
|
|
40
|
+
res.setHeader(name, value);
|
|
41
|
+
},
|
|
42
|
+
send: (body) => {
|
|
43
|
+
res.end(body);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
isBuild,
|
|
47
|
+
isGenerated
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var vite_default = mcResourcesPlugin;
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { vite_default as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const require_core = require('./core-BP2mwKSk.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/webpack.ts
|
|
4
|
+
var McResourcesPlugin = class {
|
|
5
|
+
core;
|
|
6
|
+
isGenerated;
|
|
7
|
+
isBuild;
|
|
8
|
+
isPreview;
|
|
9
|
+
outDir;
|
|
10
|
+
buildProcessed = false;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.isGenerated = false;
|
|
13
|
+
this.core = new require_core.McResourcesCore(options);
|
|
14
|
+
this.isBuild = false;
|
|
15
|
+
this.isPreview = false;
|
|
16
|
+
}
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
const ensureImageLoaderRule = () => {
|
|
19
|
+
if (!compiler.options.module) compiler.options.module = { rules: [] };
|
|
20
|
+
if (!compiler.options.module.rules) compiler.options.module.rules = [];
|
|
21
|
+
if (!compiler.options.module.rules.some((rule) => {
|
|
22
|
+
if (typeof rule === "object" && rule !== null && "test" in rule) {
|
|
23
|
+
const testRegex = rule.test;
|
|
24
|
+
if (testRegex instanceof RegExp) return testRegex.test(".png") || testRegex.test(".jpg");
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
})) compiler.options.module.rules.push({
|
|
28
|
+
test: /\.(png|jpg|jpeg|gif|webp)$/i,
|
|
29
|
+
type: "asset/resource"
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
ensureImageLoaderRule();
|
|
33
|
+
const isProduction = compiler.options.mode === "production";
|
|
34
|
+
const isServe = !!process.env.WEBPACK_SERVE;
|
|
35
|
+
this.isBuild = !isServe;
|
|
36
|
+
this.isPreview = isProduction && isServe;
|
|
37
|
+
this.outDir = compiler.options.output.path;
|
|
38
|
+
compiler.hooks.emit.tap("McResourcesPlugin", async (compilation) => {
|
|
39
|
+
if (!this.isBuild && !this.isPreview) this.core.devServerStart();
|
|
40
|
+
});
|
|
41
|
+
compiler.hooks.beforeCompile.tapAsync("McResourcesPlugin", async (compilation, callback) => {
|
|
42
|
+
if (this.isBuild && !this.buildProcessed) {
|
|
43
|
+
this.buildProcessed = true;
|
|
44
|
+
await this.core.getAssetsInBuildMode();
|
|
45
|
+
await this.core.build({ distDir: this.outDir });
|
|
46
|
+
}
|
|
47
|
+
callback();
|
|
48
|
+
});
|
|
49
|
+
if (!compiler.options.devServer) compiler.options.devServer = {};
|
|
50
|
+
const devServerConfig = compiler.options.devServer;
|
|
51
|
+
devServerConfig.setupMiddlewares = (middlewares, devServer) => {
|
|
52
|
+
if (!devServer.app) throw new Error("webpack-dev-server app is not defined");
|
|
53
|
+
devServer.app.get("/@hato810424:mc-resources-plugin/*", (req, res, next) => {
|
|
54
|
+
this.core.devServerMiddleware({
|
|
55
|
+
next,
|
|
56
|
+
req: {
|
|
57
|
+
url: req.url,
|
|
58
|
+
headers: req.headers
|
|
59
|
+
},
|
|
60
|
+
res: {
|
|
61
|
+
setStatus: (statusCode) => {
|
|
62
|
+
res.statusCode = statusCode;
|
|
63
|
+
},
|
|
64
|
+
setHeader: (name, value) => {
|
|
65
|
+
res.setHeader(name, value);
|
|
66
|
+
},
|
|
67
|
+
send: (body) => {
|
|
68
|
+
res.end(body);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
isBuild: this.isBuild,
|
|
72
|
+
isGenerated: this.isGenerated
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return middlewares;
|
|
76
|
+
};
|
|
77
|
+
compiler.options.devServer = devServerConfig;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var webpack_default = McResourcesPlugin;
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
module.exports = webpack_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as PluginOptions } from "./types-BGQHsCJS.cjs";
|
|
2
|
+
import { Compiler, WebpackPluginInstance } from "webpack";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/webpack.d.ts
|
|
5
|
+
declare class McResourcesPlugin implements WebpackPluginInstance {
|
|
6
|
+
private readonly core;
|
|
7
|
+
private isGenerated;
|
|
8
|
+
private isBuild;
|
|
9
|
+
private isPreview;
|
|
10
|
+
private outDir;
|
|
11
|
+
private buildProcessed;
|
|
12
|
+
constructor(options: PluginOptions);
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
}
|
|
15
|
+
export = McResourcesPlugin;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { t as PluginOptions } from "./types-BEv9afFy.mjs";
|
|
2
|
+
import { Compiler, WebpackPluginInstance } from "webpack";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/webpack.d.ts
|
|
5
|
+
declare class McResourcesPlugin implements WebpackPluginInstance {
|
|
6
|
+
private readonly core;
|
|
7
|
+
private isGenerated;
|
|
8
|
+
private isBuild;
|
|
9
|
+
private isPreview;
|
|
10
|
+
private outDir;
|
|
11
|
+
private buildProcessed;
|
|
12
|
+
constructor(options: PluginOptions);
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { McResourcesPlugin as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { t as McResourcesCore } from "./core-BHoK8fPV.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/webpack.ts
|
|
4
|
+
var McResourcesPlugin = class {
|
|
5
|
+
core;
|
|
6
|
+
isGenerated;
|
|
7
|
+
isBuild;
|
|
8
|
+
isPreview;
|
|
9
|
+
outDir;
|
|
10
|
+
buildProcessed = false;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.isGenerated = false;
|
|
13
|
+
this.core = new McResourcesCore(options);
|
|
14
|
+
this.isBuild = false;
|
|
15
|
+
this.isPreview = false;
|
|
16
|
+
}
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
const ensureImageLoaderRule = () => {
|
|
19
|
+
if (!compiler.options.module) compiler.options.module = { rules: [] };
|
|
20
|
+
if (!compiler.options.module.rules) compiler.options.module.rules = [];
|
|
21
|
+
if (!compiler.options.module.rules.some((rule) => {
|
|
22
|
+
if (typeof rule === "object" && rule !== null && "test" in rule) {
|
|
23
|
+
const testRegex = rule.test;
|
|
24
|
+
if (testRegex instanceof RegExp) return testRegex.test(".png") || testRegex.test(".jpg");
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
})) compiler.options.module.rules.push({
|
|
28
|
+
test: /\.(png|jpg|jpeg|gif|webp)$/i,
|
|
29
|
+
type: "asset/resource"
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
ensureImageLoaderRule();
|
|
33
|
+
const isProduction = compiler.options.mode === "production";
|
|
34
|
+
const isServe = !!process.env.WEBPACK_SERVE;
|
|
35
|
+
this.isBuild = !isServe;
|
|
36
|
+
this.isPreview = isProduction && isServe;
|
|
37
|
+
this.outDir = compiler.options.output.path;
|
|
38
|
+
compiler.hooks.emit.tap("McResourcesPlugin", async (compilation) => {
|
|
39
|
+
if (!this.isBuild && !this.isPreview) this.core.devServerStart();
|
|
40
|
+
});
|
|
41
|
+
compiler.hooks.beforeCompile.tapAsync("McResourcesPlugin", async (compilation, callback) => {
|
|
42
|
+
if (this.isBuild && !this.buildProcessed) {
|
|
43
|
+
this.buildProcessed = true;
|
|
44
|
+
await this.core.getAssetsInBuildMode();
|
|
45
|
+
await this.core.build({ distDir: this.outDir });
|
|
46
|
+
}
|
|
47
|
+
callback();
|
|
48
|
+
});
|
|
49
|
+
if (!compiler.options.devServer) compiler.options.devServer = {};
|
|
50
|
+
const devServerConfig = compiler.options.devServer;
|
|
51
|
+
devServerConfig.setupMiddlewares = (middlewares, devServer) => {
|
|
52
|
+
if (!devServer.app) throw new Error("webpack-dev-server app is not defined");
|
|
53
|
+
devServer.app.get("/@hato810424:mc-resources-plugin/*", (req, res, next) => {
|
|
54
|
+
this.core.devServerMiddleware({
|
|
55
|
+
next,
|
|
56
|
+
req: {
|
|
57
|
+
url: req.url,
|
|
58
|
+
headers: req.headers
|
|
59
|
+
},
|
|
60
|
+
res: {
|
|
61
|
+
setStatus: (statusCode) => {
|
|
62
|
+
res.statusCode = statusCode;
|
|
63
|
+
},
|
|
64
|
+
setHeader: (name, value) => {
|
|
65
|
+
res.setHeader(name, value);
|
|
66
|
+
},
|
|
67
|
+
send: (body) => {
|
|
68
|
+
res.end(body);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
isBuild: this.isBuild,
|
|
72
|
+
isGenerated: this.isGenerated
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return middlewares;
|
|
76
|
+
};
|
|
77
|
+
compiler.options.devServer = devServerConfig;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var webpack_default = McResourcesPlugin;
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { webpack_default as default };
|