webpack文件夹打包_webpack打包后dist目录下没有images文件夹?

在使用webpack配置文件进行项目打包时,发现html中引用的图片在dist目录下未生成对应的images文件夹。经过检查,问题出在url-loader配置上。limit参数设置为2048,意味着小于2048字节的图片会被内联到css或js文件中,而大于此限制的图片才会被输出到指定路径。调整url-loader配置或增加file-loader以确保所有图片都被正确打包。
摘要由CSDN通过智能技术生成

Vision

"webpack": "^3.10.0",

"webpack-dev-server": "^2.9.5"

文件结构(打包前):

webpack.config.js

const path = require('path');

const webpack = require('webpack');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const ExtractTextPlugin = require("extract-text-webpack-plugin");

var getHtmlConfig = function (name, title) {

return {

template: './demos/' + name + '.html',

filename: 'demos/' + name + '.html',

title: title,

inject: true | 'body',

hash: true,

cache: true,

chunks: ['common', name]

};

};

module.exports = {

entry: {

'common' : './js/common.js',

'a' : './js/a.js',

},

devServer: {

host: '0.0.0.0',

useLocalIp: true,

contentBase: path.resolve(__dirname, 'dist'),

compress: true,

port: 9000,

open: true

},

// 模块解析

module: {

loaders: [{

test: /\.js$/,

exclude: /node_modules/,

loader: "babel-loader"

},

{

test: /\.css$/,

use: ExtractTextPlugin.extract({

fallback: 'style-loader',

use: ['css-loader', 'px2rem-loader?remUnit=23.438&remPrecision=8', 'postcss-loader'],

})

},

{

test: /\.scss$/,

use: ExtractTextPlugin.extract({

fallback: 'style-loader',

use: ['css-loader', 'px2rem-loader?remUnit=46.875&remPrecision=8', 'sass-loader', 'postcss-loader']

})

},

{

test: /\.(png|jpg|gif|jpeg)$/,

loader: 'url-loader',

options: {

limit: 2048,

name: 'images/[name].[ext]'

}

},

{

test: /\.(eot|svg|ttf|woff|woff2|otf)$/,

loader: 'url-loader',

options: {

limit: 8192,

name: 'fonts/[name].[ext]'

}

}

]

},

externals: {

jquery: 'window.jQuery'

},

// 插件

plugins: [

new HtmlWebpackPlugin(getHtmlConfig('a', 'ab')),

new ExtractTextPlugin('css/[name].min.css')

],

// 输出

output: {

path: path.resolve(__dirname, 'dist'),

filename: 'js/[name].min.js',

}

};

问题:html文件中通过img标签引入图片,打包后dist文件夹下并没有出现images文件夹?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值