gpt4 book ai didi

javascript - 升级到 Webpack 5 后无法访问 copy-webpack-plugin 中的 list

转载 作者:行者123 更新时间:2023-12-05 00:29:48 25 4
gpt4 key购买 nike

我的配置在 webpack 版本 4.6.0 中运行良好和 webpack-assets-manifest 版本 3.1.1自从我升级到 webpack 5和 webpack-assets-manifest 到 5 .我的 manifestObject 没有获得值(value)它只是空对象
我怀疑这是因为转换函数在创建 list 之前运行
查看了 webpack-assets-manifest 的新文档,但无法正常工作
我的目标是在转换函数中访问 list 值,但看起来转换函数在生成 list 之前正在运行

var CopyWebpackPlugin = require('copy-webpack-plugin');
var SaveHashes = require('webpack-assets-manifest');

const manifest = new SaveHashes({
entrypoints: true,
entrypointsKey: 'entryPoints'
});
module.exports = {
entry: {
main: ['./src/apps/main'],
games: ['./src/apps/games'],
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: assetsUrl,
filename: 'assets/javascript/[name].[contenthash].js',
chunkFilename: 'assets/javascript/[name].[contenthash].js'
},
.
.
.
.
.
plugins: [
new CleanWebpackPlugin(),
manifest,
new CopyWebpackPlugin([
{
from: './views/**/*',
to: path.join(__dirname, 'dist'),
transform(content, path) {
// I want to access manifest here
// so that I can inject the final script(javascript bundle with content hash)
// in my view template
const manifestObject = JSON.parse(manifest);
}
}
])
]
};

最佳答案

你需要像这样导出它


const ManifestPlugin = require("webpack-manifest-plugin").WebpackManifestPlugin;

.....
new ManifestPlugin({
fileName: "asset-manifest.json",
publicPath: paths.publicUrlOrPath,
generate: (seed, files, entrypoints) => {
const manifestFiles = files.reduce((manifest, file) => {
manifest[ file.name ] = file.path;

return manifest;
}, seed);
const entrypointFiles = entrypoints.main.filter(
(fileName) => !fileName.endsWith(".map")
);

return {
files: manifestFiles,
entrypoints: entrypointFiles,
};
},
}),
它会工作 WebpackManifestPlugin是你需要的

关于javascript - 升级到 Webpack 5 后无法访问 copy-webpack-plugin 中的 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69565035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com