Webpack图片加载失效求助:ThreeJS项目无法正常加载图片
ThreeJS + Webpack 图片加载失败问题
我在ThreeJS项目中使用Webpack加载图片时遇到问题:图片无法正常加载,Sources面板中显示为带哈希值的.png文件但存在错误,页面上完全看不到图片效果。
我的Webpack配置如下:
const CopyWebpackPlugin = require("copy-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const MiniCSSExtractPlugin = require("mini-css-extract-plugin"); const path = require("path"); module.exports = { entry: path.resolve(__dirname, "../src/script.js"), output: { filename: "bundle.[contenthash].js", path: path.resolve(__dirname, "../dist"), }, devtool: "source-map", plugins: [ new CopyWebpackPlugin({ patterns: [{ from: path.resolve(__dirname, "../static") }], }), new HtmlWebpackPlugin({ template: path.resolve(__dirname, "../src/index.html"), minify: true, }), new MiniCSSExtractPlugin(), ], module: { rules: [ // HTML { test: /\.(html)$/, use: ["html-loader"], }, // JS { test: /\.js$/, exclude: /node_modules/, use: ["babel-loader"], }, // CSS { test: /\.css$/, use: [MiniCSSExtractPlugin.loader, "css-loader"], }, // Images { test: /\.(jpg|png|gif|svg)$/, use: [ { loader: "file-loader?name=[name].[ext]", options: { outputPath: "assets/images/", }, }, ], }, // Fonts { test: /\.(ttf|eot|woff|woff2)$/, use: [ { loader: "file-loader", options: { outputPath: "assets/fonts/", }, }, ], }, { test: /\.(jpg|png)$/, use: { loader: "url-loader", }, }, ], }, };
我尝试过网上的一些解决方案,但都没有效果。


内容的提问来源于stack exchange,提问作者kondziu
相关产品推荐
相关产品推荐

