add support for static assets in theme folders

This commit is contained in:
Art Lowel
2021-03-03 17:43:37 +01:00
parent 7a42a18bfb
commit 1bb2d5da29
5 changed files with 74 additions and 70 deletions

View File

@@ -5,26 +5,38 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtPlugin = require('script-ext-html-webpack-plugin');
export const copyWebpackOptions = [
{
from: path.join(__dirname, '..', 'node_modules', '@fortawesome', 'fontawesome-free', 'webfonts'),
to: path.join('assets', 'fonts'),
force: undefined
},
{
from: path.join(__dirname, '..', 'src', 'assets', 'fonts'),
to: path.join('assets', 'fonts')
}, {
from: path.join(__dirname, '..', 'src', 'assets', 'images'),
to: path.join('assets', 'images')
}, {
from: path.join(__dirname, '..', 'src', 'assets', 'i18n'),
to: path.join('assets', 'i18n')
}, {
from: path.join(__dirname, '..', 'src', 'robots.txt'),
to: path.join('robots.txt')
}
];
export const copyWebpackOptions = {
patterns: [
{
from: path.join(__dirname, '..', 'node_modules', '@fortawesome', 'fontawesome-free', 'webfonts'),
to: path.join('assets', 'fonts'),
force: undefined
},
{
from: path.join(__dirname, '..', 'src', 'assets'),
to: 'assets',
},
{
from: path.join(__dirname, '..', 'src', 'themes', '*', 'assets', '**', '*'),
to: 'assets',
noErrorOnMissing: true,
transformPath(targetPath, absolutePath) {
// use [\/|\\] to match both POSIX and Windows separators
const matches = absolutePath.match(/.*[\/|\\]themes[\/|\\]([^\/|^\\]+)[\/|\\]assets[\/|\\](.+)$/);
if (matches) {
// matches[1] is the theme name
// matches[2] is the rest of the path relative to the assets folder
// e.g. themes/custom/assets/images/logo.png will end up in assets/custom/images/logo.png
return path.join('assets', matches[1], matches[2]);
}
},
},
{
from: path.join(__dirname, '..', 'src', 'robots.txt'),
to: 'robots.txt'
}
]
};
const SCSS_LOADERS = [{
loader: 'postcss-loader',
@@ -40,7 +52,8 @@ const SCSS_LOADERS = [{
includePaths: [projectRoot('./')]
}
}
},]
},
];
export const commonExports = {
plugins: [