我使用的WebPack捆绑我的模块,并使用青菜为造型的目的在一个反应基础的应用。我怎样才能加载的WebPack在上海社会科学院样式表使用的图像(S)?
使用一个单独的样式表我设置的部件的背景图像和在index.js
加载的样式表。在样式表的所有样式被应用到该组件除了背景图片。
这里是我的示例样式表来解决这个问题会被明确要求的图像,然后创建内嵌样式反应的组分
$bg-img: url('/img/bg.jpg');
.show {
position: relative;
background: $black $bg-img center center;
width: 100%;
height: 100%;
background-size: cover;
overflow: hidden;
}
的一种方式。
img1 = document.createElement("img");
img1.src = require("./image.png");
但我想负载的所有图像从我的图像文件夹,只要我的样式表加载没有单独要求每个图像。
我的WebPack配置文件是
module.exports = {
devtool: 'source-map',
entry: {
main: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/index.js'
]
},
output: {
path: path.join(__dirname, 'public'),
publicPath: '/public/',
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.join(__dirname, 'src'),
loader: 'react-hot!babel'
},
{
test: /\.scss$/,
include: path.join(__dirname, 'sass'),
loaders: ["style", "css?sourceMap", "sass?sourceMap"]
},
{
test: /\.(png|jpg)$/,
include: path.join(__dirname, 'img'),
loader: 'url-loader?limit=10000'
} // inline base64 URLs for <=10k images, direct URLs for the rest
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
我可能会丢失一些琐碎的点。任何帮助表示赞赏。
啊你想要嵌入在CSS中的图像。很高兴你想出来了。 – Brandon
儿子......谢谢你不删除这篇文章。而且我和你在一起,这是完全不透明的文档写的方式,我认为一切低于10kb将dataurl编码,其他一切都会通过... – motleydev