build(frontend): fix frontend webpack paths
This commit is contained in:
parent
6854201b0f
commit
483f3f7e05
@ -34,8 +34,8 @@ const packageVersion = packageJson.version;
|
|||||||
import faviconJson from './config/favicon.json' assert { type: 'json' };
|
import faviconJson from './config/favicon.json' assert { type: 'json' };
|
||||||
|
|
||||||
async function webpackConfig() {
|
async function webpackConfig() {
|
||||||
const wellKnownCacheDir = path.resolve(path.dirname('.cache/well-known'));
|
const wellKnownCacheDir = path.resolve('.cache/well-known');
|
||||||
const assetsDirectory = path.resolve(path.dirname('assets'));
|
const assetsDirectory = path.resolve('assets');
|
||||||
let faviconApiVersion = undefined;
|
let faviconApiVersion = undefined;
|
||||||
|
|
||||||
if (!fs.existsSync(wellKnownCacheDir)) {
|
if (!fs.existsSync(wellKnownCacheDir)) {
|
||||||
@ -192,7 +192,7 @@ async function webpackConfig() {
|
|||||||
|
|
||||||
let cachedVersion = undefined;
|
let cachedVersion = undefined;
|
||||||
|
|
||||||
const versionFile = path.resolve(path.dirname('.well-known-cache'), `${cacheDigest}.version`);
|
const versionFile = path.resolve('.well-known-cache', `${cacheDigest}.version`);
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(versionFile)) {
|
if (fs.existsSync(versionFile)) {
|
||||||
cachedVersion = fs.readFileSync(versionFile, 'utf8');
|
cachedVersion = fs.readFileSync(versionFile, 'utf8');
|
||||||
@ -209,14 +209,14 @@ async function webpackConfig() {
|
|||||||
return Array.from(langs).map(lang => {
|
return Array.from(langs).map(lang => {
|
||||||
const faviconConfig = { versioning: { param_name: 'v', param_value: versionDigest.substr(0,10) }, ...langJsons[lang] };
|
const faviconConfig = { versioning: { param_name: 'v', param_value: versionDigest.substr(0,10) }, ...langJsons[lang] };
|
||||||
|
|
||||||
const cacheDirectory = path.resolve(path.dirname('.well-known-cache'), `${cacheDigest}-${lang}`);
|
const cacheDirectory = path.resolve('.well-known-cache', `${cacheDigest}-${lang}`);
|
||||||
|
|
||||||
if (fs.existsSync(wellKnownCacheDir)) {
|
if (fs.existsSync(wellKnownCacheDir)) {
|
||||||
console.log("Using favicons generated by nix");
|
console.log("Using favicons generated by nix");
|
||||||
return [
|
return [
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
{ from: path.resolve(wellKnownCacheDir, lang), to: path.resolve(path.dirname('well-known'), lang) }
|
{ from: path.resolve(wellKnownCacheDir, lang), to: path.resolve('well-known', lang) }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@ -225,7 +225,7 @@ async function webpackConfig() {
|
|||||||
return [
|
return [
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
{ from: cacheDirectory, to: path.resolve(path.dirname('well-known'), lang) }
|
{ from: cacheDirectory, to: path.resolve('well-known', lang) }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@ -237,23 +237,23 @@ async function webpackConfig() {
|
|||||||
return [
|
return [
|
||||||
new RealFaviconPlugin({
|
new RealFaviconPlugin({
|
||||||
faviconJson: path.relative(".", tmpobj.name),
|
faviconJson: path.relative(".", tmpobj.name),
|
||||||
outputPath: path.resolve(path.dirname('well-known'), lang),
|
outputPath: path.resolve('well-known', lang),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
{ from: 'config/robots.txt', to: path.resolve(path.dirname('well-known'), lang, 'robots.txt') },
|
{ from: 'config/robots.txt', to: path.resolve('well-known', lang, 'robots.txt') },
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
{ apply: compiler => compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
|
{ apply: compiler => compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
|
||||||
const imgFiles = glob.sync(path.resolve(path.dirname('well-known'), lang, '*.@(png)'));
|
const imgFiles = glob.sync(path.resolve('well-known', lang, '*.@(png)'));
|
||||||
const imgFilesArgs = Array.from(imgFiles).join(" ");
|
const imgFilesArgs = Array.from(imgFiles).join(" ");
|
||||||
execSync(`exiftool -overwrite_original -all= ${imgFilesArgs}`, { stdio: 'inherit' });
|
execSync(`exiftool -overwrite_original -all= ${imgFilesArgs}`, { stdio: 'inherit' });
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{ apply: compiler => compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
|
{ apply: compiler => compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
|
||||||
fs.ensureDirSync(path.dirname('.well-known-cache'));
|
fs.ensureDirSync('.well-known-cache');
|
||||||
fs.copySync(path.resolve(path.dirname('well-known'), lang), cacheDirectory);
|
fs.copySync(path.resolve('well-known', lang), cacheDirectory);
|
||||||
if (!fs.existsSync(versionFile)) {
|
if (!fs.existsSync(versionFile)) {
|
||||||
fs.writeFileSync(versionFile, faviconApiVersion, { encoding: 'utf8' });
|
fs.writeFileSync(versionFile, faviconApiVersion, { encoding: 'utf8' });
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ async function webpackConfig() {
|
|||||||
output: {
|
output: {
|
||||||
chunkFilename: '[chunkhash].js',
|
chunkFilename: '[chunkhash].js',
|
||||||
filename: '[chunkhash].js',
|
filename: '[chunkhash].js',
|
||||||
path: path.resolve(path.dirname('static'), `wp-${webpackVersion}`),
|
path: path.resolve('static', `wp-${webpackVersion}`),
|
||||||
publicPath: `/static/res/wp-${webpackVersion}/`,
|
publicPath: `/static/res/wp-${webpackVersion}/`,
|
||||||
hashFunction: 'shake256',
|
hashFunction: 'shake256',
|
||||||
hashDigestLength: 36
|
hashDigestLength: 36
|
||||||
|
|||||||
Reference in New Issue
Block a user