webpack打包img和css时如何保留子文件夹?
1.使用url-loader和extract-text-webpack-plugin这俩插件处理css和img时最后打包后如何保留子目录结构呢?而不是全部在css/,images/下?
2.比如我有这样的结构
我目前打包是所有css/都通过这个extract-text-webpack-plugin的设置,(下图)
打包在css/下了,之前的common文件夹没有了,我还想实现打包后保留common子文件夹目录,该如何设置呢?还有img图片也是想保留子目录怎么设置?
图片时用url-loader处理的。
3.我还有个疑问webpack如何抽取公共的css呢?比如我在a.js require('base.css'),同样在b.js也 require('base.css'),这样这个base.css就会被extract-text-webpack-plugin打包到两个入口的css中了?怎么设置可以抽取公共的css出来呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
You can accomplish both of these thing but it varies per plugin/loader.
ExtractTextWebpackPlugin
For extract-text-webpack-plugin, the filename property can actually be a function. It passes
getPath
to process the format likecss/[name].css
and returns the real file name,css/js/a.css
. You can replacecss/js
withcss
then you will get the new pathcss/a.css
.File Loader
For
file-loader
you can specify custom output and public paths by using theoutputPath
,publicPath
anduseRelativePath
query name parameters (and also could be just option properties too):Shared CSS
When you use
webpack.optimize.CommonsChunkPlugin
, it should behave the same way with CSS as it does with JavaScript. You can find more information about its usage at our new webpack docs page (there is also a Chinese version click top right corner)Hopefully this helps!