If we have
.
├── src
| ├── css
| | └── style.css
| ├── images
| | └── image.png
| └── js
| └── main.js
.
/* src/css/style.css*/
body{
background:url(../images/image.png)
}
/* src/js/main.js*/
require('../css/style.css')
I want compile to dist
folder as the same structure like
.
├── dist
| ├── css
| | └── main-bundle.css
| ├── assets
| | └── image.png
| └── js
| └── main-bundle.js
├── src
. └── ...
so we wrote webpack.config.js using ExtractTextPlugin to extract css file seperately like
entry: {
main:"main.js"
},
output: {
path: path.join(__dirname, "dist"),
filename: "./js/[name].bundle.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") },
{ test: /\.png$/, loader: "file-loader?name=./assets/[name].[ext]" }
],
plugins: [
new ExtractTextPlugin("./css/[name]-bundle.css")
]
}
So we got
/* dist/css/main-bundle.css*/
body{
background:url(./assets/image.png)
}
But actually ,we want it to be url(../assets/image.png)
when I config png loader file-loader?name=../images/[name].[ext]
it put the image file to outside dist folder instead. I have found out that it’s impossible to set url correctly
Thank you for your approach I’ve never use manifest before it seems useful for me
I’ve already carelessly hacked
file-loader
I separate url from emitFile method by replacing with another parameter
to
that means url() in css would be written withname
but the image file will emit to different locationto
using