build(frontend): fix webpack config
This commit is contained in:
parent
f4ee39c717
commit
c7d5cbfb49
@ -27,4 +27,4 @@ RUN make node_modules
|
|||||||
RUN make well-known
|
RUN make well-known
|
||||||
|
|
||||||
ENV FRADRIVE_MAKE_TARGET=frontend-watch
|
ENV FRADRIVE_MAKE_TARGET=frontend-watch
|
||||||
ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} CHROME_BIN=${CHROME_BIN}
|
ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} CHROME_BIN=${CHROME_BIN}
|
||||||
|
|||||||
@ -3,12 +3,12 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import path from 'path';
|
import { resolve, join, relative } from 'node:path';
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
tmp.setGracefulCleanup();
|
tmp.setGracefulCleanup();
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { glob, globSync } from 'glob';
|
import { glob, globSync } from 'glob';
|
||||||
import execSync from 'child_process';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
||||||
@ -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('.cache/well-known');
|
const wellKnownCacheDir = resolve('.cache/well-known');
|
||||||
const assetsDirectory = path.resolve('assets');
|
const assetsDirectory = resolve('assets');
|
||||||
let faviconApiVersion = undefined;
|
let faviconApiVersion = undefined;
|
||||||
|
|
||||||
if (!fs.existsSync(wellKnownCacheDir)) {
|
if (!fs.existsSync(wellKnownCacheDir)) {
|
||||||
@ -111,8 +111,8 @@ async function webpackConfig() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
entry: {
|
entry: {
|
||||||
main: [ path.resolve('frontend/src/polyfill.js'),
|
main: [ resolve('frontend/src/polyfill.js'),
|
||||||
path.resolve('frontend/src/main.js'),
|
resolve('frontend/src/main.js'),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -125,14 +125,14 @@ async function webpackConfig() {
|
|||||||
ignoreOrder: false, // Enable to remove warnings about conflicting order
|
ignoreOrder: false, // Enable to remove warnings about conflicting order
|
||||||
}),
|
}),
|
||||||
new WebpackManifestPlugin({
|
new WebpackManifestPlugin({
|
||||||
fileName: path.resolve('config/webpack.yml'),
|
fileName: resolve('config/webpack.yml'),
|
||||||
publicPath: `wp-${webpackVersion}`,
|
publicPath: `wp-${webpackVersion}`,
|
||||||
generate: (seed, files, entrypoints) => Object.keys(entrypoints).reduce((acc, fs) => ({...acc, [fs]: files.filter(file => entrypoints[fs].filter(basename => !(/\.map$/.test(basename))).some(basename => file.path.endsWith(basename))).filter(file => file.isInitial).map(file => file.path)}), {}),
|
generate: (seed, files, entrypoints) => Object.keys(entrypoints).reduce((acc, fs) => ({...acc, [fs]: files.filter(file => entrypoints[fs].filter(basename => !(/\.map$/.test(basename))).some(basename => file.path.endsWith(basename))).filter(file => file.isInitial).map(file => file.path)}), {}),
|
||||||
serialize: yaml.dump
|
serialize: yaml.dump
|
||||||
}),
|
}),
|
||||||
new CleanWebpackPlugin({
|
new CleanWebpackPlugin({
|
||||||
cleanOnceBeforeBuildPatterns: [ path.resolve('static'),
|
cleanOnceBeforeBuildPatterns: [ resolve('static'),
|
||||||
path.resolve('well-known'),
|
resolve('well-known'),
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
new webpack.IgnorePlugin({
|
new webpack.IgnorePlugin({
|
||||||
@ -180,8 +180,8 @@ async function webpackConfig() {
|
|||||||
cacheHash.update(JSON.stringify(langJsons));
|
cacheHash.update(JSON.stringify(langJsons));
|
||||||
|
|
||||||
const cacheFiles = new Set([
|
const cacheFiles = new Set([
|
||||||
...(Array.from(langs).map(lang => path.resolve(langJsons[lang].masterPicture))),
|
...(Array.from(langs).map(lang => resolve(langJsons[lang].masterPicture))),
|
||||||
path.resolve('config/robots.txt'),
|
resolve('config/robots.txt'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (const cacheFile of cacheFiles) {
|
for (const cacheFile of cacheFiles) {
|
||||||
@ -192,7 +192,7 @@ async function webpackConfig() {
|
|||||||
|
|
||||||
let cachedVersion = undefined;
|
let cachedVersion = undefined;
|
||||||
|
|
||||||
const versionFile = path.resolve('.well-known-cache', `${cacheDigest}.version`);
|
const versionFile = 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('.well-known-cache', `${cacheDigest}-${lang}`);
|
const cacheDirectory = 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('well-known', lang) }
|
{ from: resolve(wellKnownCacheDir, lang), to: resolve('well-known', lang) }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@ -225,7 +225,7 @@ async function webpackConfig() {
|
|||||||
return [
|
return [
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
{ from: cacheDirectory, to: path.resolve('well-known', lang) }
|
{ from: cacheDirectory, to: resolve('well-known', lang) }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@ -236,24 +236,24 @@ async function webpackConfig() {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
new RealFaviconPlugin({
|
new RealFaviconPlugin({
|
||||||
faviconJson: path.relative(".", tmpobj.name),
|
faviconJson: relative(".", tmpobj.name),
|
||||||
outputPath: path.resolve('well-known', lang),
|
outputPath: resolve('well-known', lang),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
{ from: 'config/robots.txt', to: path.resolve('well-known', lang, 'robots.txt') },
|
{ from: 'config/robots.txt', to: resolve('well-known', lang, 'robots.txt') },
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
{ apply: compiler => compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
|
{ apply: compiler => compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
|
||||||
const imgFiles = globSync(path.resolve('well-known', lang) + '/*.@(png)');
|
const imgFiles = globSync(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('.well-known-cache');
|
fs.ensureDirSync('.well-known-cache');
|
||||||
fs.copySync(path.resolve('well-known', lang), cacheDirectory);
|
fs.copySync(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('static', `wp-${webpackVersion}`),
|
path: resolve('static', `wp-${webpackVersion}`),
|
||||||
publicPath: `/static/res/wp-${webpackVersion}/`,
|
publicPath: `/static/res/wp-${webpackVersion}/`,
|
||||||
hashFunction: 'shake256',
|
hashFunction: 'shake256',
|
||||||
hashDigestLength: 36
|
hashDigestLength: 36
|
||||||
@ -293,7 +293,7 @@ async function webpackConfig() {
|
|||||||
|
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
|
|
||||||
recordsPath: path.join(path.resolve('records.json')),
|
recordsPath: join(resolve('records.json')),
|
||||||
|
|
||||||
performance: {
|
performance: {
|
||||||
assetFilter: (assetFilename) => !(/\.(map|svg|ttf|eot)$/.test(assetFilename))
|
assetFilter: (assetFilename) => !(/\.(map|svg|ttf|eot)$/.test(assetFilename))
|
||||||
|
|||||||
Reference in New Issue
Block a user