2020-06-23 13:44:14 +02:00
|
|
|
/*
|
|
|
|
|
2022-04-13 22:17:59 +02:00
|
|
|
Copyright (c) 2018 - 2022 PhotoPrism UG. All rights reserved.
|
2020-06-23 13:44:14 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
2022-02-21 16:10:06 +01:00
|
|
|
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
|
|
|
|
<https://docs.photoprism.app/license/agpl>
|
2020-06-23 13:44:14 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
2022-02-21 16:10:06 +01:00
|
|
|
The AGPL is supplemented by our Trademark and Brand Guidelines,
|
|
|
|
which describe how our Brand Assets may be used:
|
|
|
|
<https://photoprism.app/trademark>
|
2020-06-23 13:44:14 +02:00
|
|
|
|
2022-04-13 22:17:59 +02:00
|
|
|
Feel free to send an email to hello@photoprism.app if you have questions,
|
2020-06-23 13:44:14 +02:00
|
|
|
want to support our work, or just want to say hello.
|
|
|
|
|
|
|
|
Additional information can be found in our Developer Guide:
|
2022-02-27 17:32:54 +01:00
|
|
|
<https://docs.photoprism.app/developer-guide/>
|
2020-06-23 13:44:14 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-05-09 06:48:10 +02:00
|
|
|
const path = require("path");
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
2021-07-26 00:05:50 +02:00
|
|
|
const ESLintPlugin = require("eslint-webpack-plugin");
|
2022-01-18 12:26:33 +01:00
|
|
|
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
|
2021-07-12 19:25:37 +02:00
|
|
|
const OfflinePlugin = require("@lcdp/offline-plugin");
|
2019-05-09 06:48:10 +02:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const isDev = process.env.NODE_ENV !== "production";
|
2022-02-21 16:10:06 +01:00
|
|
|
const isCustom = !!process.env.CUSTOM_SRC;
|
|
|
|
const appName = process.env.CUSTOM_NAME ? process.env.CUSTOM_NAME : "PhotoPrism";
|
2021-07-12 19:25:37 +02:00
|
|
|
const { VueLoaderPlugin } = require("vue-loader");
|
2018-07-27 17:31:39 +02:00
|
|
|
|
2019-05-28 01:18:27 +02:00
|
|
|
const PATHS = {
|
2022-02-21 16:10:06 +01:00
|
|
|
src: path.join(__dirname, "src"),
|
|
|
|
css: path.join(__dirname, "src/css"),
|
|
|
|
modules: path.join(__dirname, "node_modules"),
|
2020-12-18 14:42:36 +01:00
|
|
|
app: path.join(__dirname, "src/app.js"),
|
|
|
|
share: path.join(__dirname, "src/share.js"),
|
|
|
|
build: path.join(__dirname, "../assets/static/build"),
|
2022-01-16 15:33:29 +01:00
|
|
|
public: "./",
|
2019-05-28 01:18:27 +02:00
|
|
|
};
|
|
|
|
|
2022-02-21 16:10:06 +01:00
|
|
|
if (isCustom) {
|
|
|
|
PATHS.custom = path.join(__dirname, process.env.CUSTOM_SRC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDev) {
|
|
|
|
console.log(`Starting ${appName} DEVELOPMENT build. Please wait.`);
|
|
|
|
} else {
|
|
|
|
console.log(`Starting ${appName} PRODUCTION build. Please wait.`);
|
|
|
|
}
|
|
|
|
|
2018-07-27 17:31:39 +02:00
|
|
|
const config = {
|
2020-12-18 14:42:36 +01:00
|
|
|
mode: isDev ? "development" : "production",
|
|
|
|
devtool: isDev ? "inline-source-map" : false,
|
2021-07-12 19:25:37 +02:00
|
|
|
optimization: {
|
|
|
|
minimize: !isDev,
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
entry: {
|
|
|
|
app: PATHS.app,
|
|
|
|
share: PATHS.share,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: PATHS.build,
|
2022-01-16 15:30:15 +01:00
|
|
|
publicPath: PATHS.public,
|
2022-01-18 12:26:33 +01:00
|
|
|
filename: "[name].[contenthash].js",
|
|
|
|
clean: true,
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
resolve: {
|
2022-02-21 16:10:06 +01:00
|
|
|
modules: isCustom ? [PATHS.custom, PATHS.src, PATHS.modules] : [PATHS.src, PATHS.modules],
|
|
|
|
preferRelative: true,
|
2020-12-18 14:42:36 +01:00
|
|
|
alias: {
|
|
|
|
vue: isDev ? "vue/dist/vue.js" : "vue/dist/vue.min.js",
|
2018-07-27 17:31:39 +02:00
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
2022-01-18 12:26:33 +01:00
|
|
|
filename: "[name].[contenthash].css",
|
2021-07-12 19:25:37 +02:00
|
|
|
experimentalUseImportModule: false,
|
2020-12-18 14:42:36 +01:00
|
|
|
}),
|
2022-01-18 12:26:33 +01:00
|
|
|
new WebpackManifestPlugin({
|
|
|
|
fileName: "assets.json",
|
|
|
|
publicPath: "",
|
|
|
|
}),
|
2021-07-12 19:25:37 +02:00
|
|
|
new webpack.ProgressPlugin(),
|
|
|
|
new VueLoaderPlugin(),
|
2021-07-13 22:54:03 +02:00
|
|
|
new OfflinePlugin({
|
|
|
|
relativePaths: false,
|
|
|
|
publicPath: "/",
|
2021-07-13 23:07:02 +02:00
|
|
|
excludes: ["**/*.txt", "**/*.css", "**/*.js", "**/*.*"],
|
2021-07-13 22:54:03 +02:00
|
|
|
rewrites: function (asset) {
|
|
|
|
return "/static/build/" + asset;
|
|
|
|
},
|
|
|
|
}),
|
2020-12-18 14:42:36 +01:00
|
|
|
],
|
|
|
|
performance: {
|
|
|
|
hints: isDev ? false : "error",
|
2022-10-13 22:18:27 +02:00
|
|
|
maxEntrypointSize: 5000000,
|
|
|
|
maxAssetSize: 5000000,
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
2022-02-21 16:10:06 +01:00
|
|
|
include: isCustom ? [PATHS.custom, PATHS.src] : [PATHS.src],
|
2021-07-12 19:25:37 +02:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: "vue-loader",
|
|
|
|
options: {
|
|
|
|
loaders: {
|
|
|
|
js: "babel-loader",
|
|
|
|
css: "css-loader",
|
|
|
|
},
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
2021-07-12 19:25:37 +02:00
|
|
|
],
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
2022-02-21 16:10:06 +01:00
|
|
|
include: PATHS.src,
|
2020-12-18 14:42:36 +01:00
|
|
|
exclude: (file) => /node_modules/.test(file),
|
2021-07-12 19:25:37 +02:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: "babel-loader",
|
|
|
|
options: {
|
|
|
|
sourceMap: isDev,
|
|
|
|
compact: false,
|
|
|
|
presets: ["@babel/preset-env"],
|
|
|
|
plugins: [
|
|
|
|
"@babel/plugin-proposal-object-rest-spread",
|
|
|
|
"@babel/plugin-proposal-class-properties",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2022-07-11 03:13:09 +02:00
|
|
|
include: isCustom ? [PATHS.custom, PATHS.css] : [PATHS.css],
|
2020-12-18 14:42:36 +01:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
2022-01-16 15:30:15 +01:00
|
|
|
publicPath: PATHS.public,
|
2018-07-27 17:31:39 +02:00
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
2021-07-12 19:25:37 +02:00
|
|
|
{
|
|
|
|
loader: "css-loader",
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"resolve-url-loader",
|
|
|
|
{
|
|
|
|
loader: "postcss-loader",
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
postcssOptions: {
|
|
|
|
config: path.resolve(__dirname, "./postcss.config.js"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
include: /node_modules/,
|
2021-07-12 19:25:37 +02:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
2022-01-16 15:30:15 +01:00
|
|
|
publicPath: PATHS.public,
|
2021-07-12 19:25:37 +02:00
|
|
|
},
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
{
|
|
|
|
loader: "css-loader",
|
2021-07-12 19:25:37 +02:00
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
2021-07-12 19:25:37 +02:00
|
|
|
"resolve-url-loader",
|
2020-12-18 14:42:36 +01:00
|
|
|
{
|
|
|
|
loader: "postcss-loader",
|
|
|
|
options: {
|
2021-07-12 19:25:37 +02:00
|
|
|
sourceMap: true,
|
|
|
|
postcssOptions: {
|
|
|
|
config: path.resolve(__dirname, "./postcss.config.js"),
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
2018-07-27 17:31:39 +02:00
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: [
|
2021-07-12 19:25:37 +02:00
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
2022-01-16 15:30:15 +01:00
|
|
|
publicPath: PATHS.public,
|
2021-07-12 19:25:37 +02:00
|
|
|
},
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
{
|
|
|
|
loader: "css-loader",
|
2021-07-12 19:25:37 +02:00
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
2021-07-12 19:25:37 +02:00
|
|
|
"resolve-url-loader",
|
2020-12-18 14:42:36 +01:00
|
|
|
{
|
|
|
|
loader: "postcss-loader",
|
|
|
|
options: {
|
2021-07-12 19:25:37 +02:00
|
|
|
sourceMap: true,
|
|
|
|
postcssOptions: {
|
|
|
|
config: path.resolve(__dirname, "./postcss.config.js"),
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
2018-07-27 17:31:39 +02:00
|
|
|
},
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
"sass-loader",
|
2018-07-27 17:31:39 +02:00
|
|
|
],
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|jpeg|gif)$/,
|
2022-01-16 15:30:15 +01:00
|
|
|
type: "asset/resource",
|
|
|
|
dependency: { not: ["url"] },
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
|
2022-01-16 15:30:15 +01:00
|
|
|
type: "asset/resource",
|
|
|
|
dependency: { not: ["url"] },
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.svg/,
|
2022-01-21 08:40:22 +01:00
|
|
|
type: "asset/resource",
|
|
|
|
dependency: { not: ["url"] },
|
2020-12-18 14:42:36 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-07-27 17:31:39 +02:00
|
|
|
};
|
|
|
|
|
2022-01-16 15:30:15 +01:00
|
|
|
// Don't create sourcemap for production builds.
|
2019-05-07 15:41:33 +02:00
|
|
|
if (isDev) {
|
2020-12-18 14:42:36 +01:00
|
|
|
const devToolPlugin = new webpack.SourceMapDevToolPlugin({
|
|
|
|
filename: "[file].map",
|
|
|
|
});
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2020-12-18 14:42:36 +01:00
|
|
|
config.plugins.push(devToolPlugin);
|
2021-07-26 00:05:50 +02:00
|
|
|
|
|
|
|
const esLintPlugin = new ESLintPlugin({
|
|
|
|
formatter: require("eslint-formatter-pretty"),
|
|
|
|
extensions: ["js"],
|
|
|
|
});
|
|
|
|
|
|
|
|
config.plugins.push(esLintPlugin);
|
2018-07-27 17:31:39 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 15:41:33 +02:00
|
|
|
module.exports = config;
|