Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: convert require to await import

Abdullah Attacae3f7354ef9
diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts
index db353923f..b7580d74f 100644
--- a/apps/web/vite.config.ts
+++ b/apps/web/vite.config.ts
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { defineConfig } from "vite";
+import { Plugin, defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import svgrPlugin from "vite-plugin-svgr";
import envCompatible from "vite-plugin-env-compatible";
@@ -89,6 +89,7 @@ export default defineConfig({
}
},
plugins: [
+ requireTransformPlugin(),
...(isDesktop && process.env.NODE_ENV === "production"
? []
: [
@@ -115,3 +116,17 @@ export default defineConfig({
})
]
});
+
+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"
+ };
+}