Skip to content

Commit

Permalink
Preserve images and fonts directory structure in dist/ and keep vendo…
Browse files Browse the repository at this point in the history
…r ones in a new vendor directory
  • Loading branch information
atanas-dev committed Jul 11, 2020
1 parent 94935d7 commit 90b0910
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion resources/build/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,20 @@ module.exports.filehash = (file) => {
return hash.digest('hex');
};

module.exports.filehashFilter = file => `[name].${module.exports.filehash(file).substr(0, 10)}.[ext]`;
module.exports.filehasher = (relativeTo = null) => (file) => {
const resourcesDir = path.normalize(exports.srcPath()) + path.sep;
const isUserFile = path.normalize(file).substr(0, resourcesDir.length) === resourcesDir;
let filepath = 'vendor';

if (isUserFile) {
filepath = '';

if (relativeTo !== null) {
filepath = path.relative(relativeTo, path.dirname(file));
}
}

filepath += filepath ? '/' : '';

return `${filepath}[name].${module.exports.filehash(file).substr(0, 10)}.[ext]`;
};
4 changes: 2 additions & 2 deletions resources/build/webpack.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = {
{
loader: 'file-loader',
options: {
name: utils.filehashFilter,
name: utils.filehasher(utils.srcImagesPath()),
outputPath: 'images',
},
},
Expand Down Expand Up @@ -198,7 +198,7 @@ module.exports = {
{
loader: 'file-loader',
options: {
name: utils.filehashFilter,
name: utils.filehasher(utils.srcFontsPath()),
outputPath: 'fonts',
},
},
Expand Down
4 changes: 2 additions & 2 deletions resources/build/webpack.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ module.exports = {
{
loader: 'file-loader',
options: {
name: utils.filehashFilter,
name: utils.filehasher(utils.srcImagesPath()),
outputPath: 'images',
},
},
Expand Down Expand Up @@ -227,7 +227,7 @@ module.exports = {
{
loader: 'file-loader',
options: {
name: utils.filehashFilter,
name: utils.filehasher(utils.srcFontsPath()),
outputPath: 'fonts',
},
},
Expand Down

0 comments on commit 90b0910

Please sign in to comment.