我正在使用一个节点库,其中包含一个css文件,该css文件加载这样的图像
background-image: url("image.png");
Run Code Online (Sandbox Code Playgroud)
在http:// localhost:9000 /处请求文件“ image.png” (根目录)很脏,无法在项目的整个根目录中包含图像。
另外我还有另一个问题,我不知道为什么模块的图像文件没有自动复制到构建文件夹,仅当我手动将图像文件复制到构建文件夹时才起作用。使用Webpack配置参数时,我正在使用该功能将映像复制到根目录,但是它为它们添加了随机名称,因此我不想在根目录中使用它们。
我希望将所有加载的图像复制到带有原始文件名的build文件夹内的“ img”子文件夹中,并在此处进行请求,因此根目录不会弄脏那里的所有文件。
这是我的webpack配置文件:
var webpack = require('webpack');
var WebpackNotifierPlugin = require('webpack-notifier');
"use strict";
module.exports = {
entry: "./source/typescript/Main.ts",
output: {
filename: "./js/bundle.js"
},
devtool: "inline-source-map",
devServer: {
contentBase: ".",
host: "localhost",
port: 9000,
open: true
},
module: {
rules: [
{
test:/\.(s*)css$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
url: false
}
},
{
loader: "sass-loader"
}
]
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: …Run Code Online (Sandbox Code Playgroud)