2023-06-12 11:49:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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 General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-07-25 08:02:57 +05:00
|
|
|
import { Plugin, defineConfig } from "vite";
|
2023-06-12 11:49:37 +05:00
|
|
|
import react from "@vitejs/plugin-react-swc";
|
|
|
|
|
import svgrPlugin from "vite-plugin-svgr";
|
|
|
|
|
import envCompatible from "vite-plugin-env-compatible";
|
2023-07-12 06:51:14 +05:00
|
|
|
import { VitePWA } from "vite-plugin-pwa";
|
2023-06-22 13:25:56 +05:00
|
|
|
import autoprefixer from "autoprefixer";
|
2023-07-12 06:51:14 +05:00
|
|
|
import { WEB_MANIFEST } from "./web-manifest";
|
|
|
|
|
import { execSync } from "child_process";
|
|
|
|
|
import { version } from "./package.json";
|
2023-06-12 11:49:37 +05:00
|
|
|
|
2023-07-12 06:51:14 +05:00
|
|
|
const gitHash = (() => {
|
|
|
|
|
try {
|
|
|
|
|
return execSync("git rev-parse --short HEAD").toString().trim();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return process.env.GIT_HASH || "gitless";
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
const appVersion = version.replaceAll(".", "");
|
2023-06-16 19:10:02 +05:00
|
|
|
const isTesting =
|
2023-07-12 06:51:14 +05:00
|
|
|
process.env.TEST === "true" || process.env.NODE_ENV === "development";
|
|
|
|
|
const isDesktop = process.env.PLATFORM === "desktop";
|
2023-06-20 17:49:23 +05:00
|
|
|
|
2023-06-12 11:49:37 +05:00
|
|
|
export default defineConfig({
|
|
|
|
|
envPrefix: "REACT_APP_",
|
|
|
|
|
build: {
|
2023-07-03 06:47:28 +05:00
|
|
|
target: isDesktop ? "esnext" : "modules",
|
2023-06-12 11:49:37 +05:00
|
|
|
outDir: "build",
|
|
|
|
|
minify: "esbuild",
|
|
|
|
|
cssMinify: true,
|
|
|
|
|
emptyOutDir: true,
|
2023-07-12 06:51:14 +05:00
|
|
|
sourcemap: isTesting,
|
2023-07-08 11:13:48 +05:00
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
assetFileNames: "assets/[name]-[hash:12][extname]",
|
2023-07-12 06:51:14 +05:00
|
|
|
chunkFileNames: "assets/[name]-[hash:12].js"
|
2023-07-08 11:13:48 +05:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-12 11:49:37 +05:00
|
|
|
},
|
2023-07-12 06:51:14 +05:00
|
|
|
define: {
|
|
|
|
|
GIT_HASH: `"${gitHash}"`,
|
|
|
|
|
APP_VERSION: `"${appVersion}"`,
|
|
|
|
|
PUBLIC_URL: `"${process.env.PUBLIC_URL || ""}"`,
|
|
|
|
|
IS_DESKTOP_APP: isDesktop,
|
|
|
|
|
PLATFORM: `"${process.env.PLATFORM}"`,
|
|
|
|
|
IS_TESTING: process.env.TEST === "true",
|
|
|
|
|
IS_BETA: process.env.BETA === "true"
|
|
|
|
|
},
|
2023-06-12 11:49:37 +05:00
|
|
|
logLevel: process.env.NODE_ENV === "production" ? "warn" : "info",
|
|
|
|
|
resolve: {
|
2023-07-03 06:47:28 +05:00
|
|
|
dedupe: ["react", "react-dom", "@mdi/js", "@mdi/react", "@emotion/react"],
|
|
|
|
|
|
|
|
|
|
alias: [
|
|
|
|
|
{
|
|
|
|
|
find: /desktop-bridge/gm,
|
|
|
|
|
replacement: isDesktop
|
|
|
|
|
? "desktop-bridge/index.desktop"
|
|
|
|
|
: "desktop-bridge/index"
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-06-12 11:49:37 +05:00
|
|
|
},
|
|
|
|
|
server: {
|
|
|
|
|
port: 3000
|
|
|
|
|
},
|
|
|
|
|
worker: {
|
2023-07-26 12:42:10 +05:00
|
|
|
format: "es",
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
inlineDynamicImports: true
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-12 11:49:37 +05:00
|
|
|
},
|
2023-06-22 13:25:56 +05:00
|
|
|
css: {
|
|
|
|
|
postcss: {
|
|
|
|
|
plugins: [autoprefixer()]
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-06-12 11:49:37 +05:00
|
|
|
plugins: [
|
2023-07-25 08:02:57 +05:00
|
|
|
requireTransformPlugin(),
|
2023-06-20 17:50:23 +05:00
|
|
|
...(isDesktop && process.env.NODE_ENV === "production"
|
2023-07-03 06:47:28 +05:00
|
|
|
? []
|
2023-06-22 15:28:29 +05:00
|
|
|
: [
|
|
|
|
|
VitePWA({
|
|
|
|
|
strategies: "injectManifest",
|
|
|
|
|
minify: true,
|
|
|
|
|
manifest: WEB_MANIFEST,
|
|
|
|
|
injectRegister: null,
|
|
|
|
|
srcDir: "src",
|
2023-07-12 06:51:14 +05:00
|
|
|
filename: "service-worker.ts"
|
2023-06-22 15:28:29 +05:00
|
|
|
})
|
|
|
|
|
]),
|
2023-06-12 11:49:37 +05:00
|
|
|
react({
|
|
|
|
|
plugins: isTesting
|
|
|
|
|
? undefined
|
|
|
|
|
: [["swc-plugin-react-remove-properties", {}]]
|
|
|
|
|
}),
|
|
|
|
|
envCompatible(),
|
|
|
|
|
svgrPlugin({
|
|
|
|
|
svgrOptions: {
|
|
|
|
|
icon: true
|
|
|
|
|
// ...svgr options (https://react-svgr.com/docs/options/)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2023-07-25 08:02:57 +05:00
|
|
|
|
|
|
|
|
function requireTransformPlugin(): Plugin {
|
|
|
|
|
return {
|
|
|
|
|
transform(code, id) {
|
|
|
|
|
if (/\/node_modules\//g.test(id)) return;
|
|
|
|
|
if (!/require/.test(code)) return;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
code: code.replace(/require\(/gm, "await import(")
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
name: "require-transform-plugin"
|
|
|
|
|
};
|
|
|
|
|
}
|