我认为Webpacking错误。在我的Webpack配置中,我有一个模块规则,可以在scss文件中遇到文件时加载文件,并且我还使用Copyplugin复制了大量其他图像。
问题是,当我在开发中运行Webpack并将“ watch”设置为true时,文件加载器将删除dist文件夹中的所有内容,然后复制SCSS文件中引用的图像。因此,通过Copyplugin复制的所有其他内容都将被删除。
我应该以其他方式处理SCSS / JS中引用的图像吗?理想情况下,我将忽略SCSS / JS中对这些东西的所有引用,而只是通过Copyplugin手动复制文件
这是我的配置:
module.exports = {
mode: 'development',watch: true,entry: {
frontend: './_src/entry.js',},output: {
filename: 'js/[name].js',path: path.resolve(__dirname,paths.distRoot),module: {
rules: [
// js
{
test: /\.js$/,exclude: /node_modules/,use: {
loader: 'babel-loader',options: {
presets: ['@babel/preset-env']
},// css
{
test: /\.css$/,use: [
{ loader: MiniCssExtractPlugin.loader },{ loader: 'css-loader' },],// scss
{
test: /\.scss$/,// css
{
loader: 'css-loader',options: { sourceMap: true },// autoprefix things
{
loader: 'postcss-loader',options: {
ident: 'postcss',sourceMap: true,plugins: [
autoprefixer({ browsers: ['last 2 version'] }),// sass
{
loader: 'sass-loader',options: {
includePaths: [
paths.npmRoot + '/font-awesome',paths.srcRoot + '/scss',paths.npmRoot,// fonts
{
test: /\.(woff(2)?|ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,loader: 'file-loader',options: {
name: '[name].[ext]',outputPath: 'fonts',publicPath: '../fonts',// images
{
test: /\.(jpg|png|svg|gif)$/,loader: 'url-loader',options: {
limit: 1,name: '[name].[ext]',outputPath: 'img',publicPath: '../img',plugins: [
new CleanWebpackPlugin(),new webpack.HotModuleReplacementPlugin(),new MiniCssExtractPlugin({
filename: 'css/[name].css',}),new Copyplugin([
{
from: path.resolve(__dirname,paths.srcRoot + '/img'),to: path.resolve(__dirname,paths.distRoot + '/img'),copyUnmodified: true,]),new (webpack.optimize.OccurenceOrderPlugin || webpack.optimize.OccurrenceOrderPlugin)(),};