2025-09-15 00:24:00 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { RawSource } = require("webpack-sources");
|
|
|
|
const webpack = require("../../../../");
|
|
|
|
|
2025-09-15 00:44:05 +08:00
|
|
|
/** @typedef {import("../../../../lib/Compiler")} Compiler */
|
|
|
|
|
2025-09-15 00:24:00 +08:00
|
|
|
class CopyPlugin {
|
2025-09-15 00:44:05 +08:00
|
|
|
/**
|
|
|
|
* Apply the plugin
|
|
|
|
* @param {Compiler} compiler the compiler instance
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2025-09-15 00:24:00 +08:00
|
|
|
apply(compiler) {
|
|
|
|
const hookOptions = {
|
|
|
|
name: "MockCopyPlugin",
|
|
|
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
|
|
};
|
|
|
|
|
|
|
|
compiler.hooks.thisCompilation.tap(hookOptions, (compilation) => {
|
2025-09-15 00:44:05 +08:00
|
|
|
compilation.hooks.processAssets.tap(hookOptions, () => {
|
|
|
|
const output = "// some compilation result\n";
|
|
|
|
compilation.emitAsset("third.party.js", new RawSource(output));
|
|
|
|
});
|
2025-09-15 00:24:00 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-10-07 00:39:29 +08:00
|
|
|
/** @type {import("../../../../").Configuration[]} */
|
|
|
|
module.exports = [
|
|
|
|
{
|
|
|
|
node: {
|
|
|
|
__dirname: false,
|
|
|
|
__filename: false
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
publicPath: "/app/",
|
|
|
|
chunkFilename: "[name].[contenthash].js",
|
|
|
|
assetModuleFilename: "[name].[contenthash][ext][query]"
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CopyPlugin(),
|
|
|
|
new webpack.ManifestPlugin({
|
|
|
|
filename: "foo.json"
|
|
|
|
})
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.txt$/,
|
|
|
|
type: "asset/resource"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.png$/,
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "file-loader.[ext]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2025-09-15 00:24:00 +08:00
|
|
|
},
|
2025-10-07 00:39:29 +08:00
|
|
|
{
|
|
|
|
entry: "./index-2.js",
|
|
|
|
node: {
|
|
|
|
__dirname: false,
|
|
|
|
__filename: false
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
publicPath: (_data) => "/dist/",
|
|
|
|
chunkFilename: "[name].[contenthash].js",
|
|
|
|
assetModuleFilename: "[name].[contenthash][ext][query]"
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CopyPlugin(),
|
|
|
|
new webpack.ManifestPlugin({
|
|
|
|
filename: "bar.json"
|
|
|
|
})
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.txt$/,
|
|
|
|
type: "asset/resource"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.png$/,
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "file-loader.[ext]"
|
|
|
|
}
|
2025-09-15 00:24:00 +08:00
|
|
|
}
|
2025-10-07 00:39:29 +08:00
|
|
|
]
|
|
|
|
}
|
2025-09-15 00:24:00 +08:00
|
|
|
}
|
2025-10-07 00:39:29 +08:00
|
|
|
];
|