mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
web: convert require to await import
This commit is contained in:
committed by
Abdullah Atta
parent
75e62a3fac
commit
cae3f7354e
@@ -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"
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user