Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: add plugin in build to replace CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
eyworldwide committed Nov 10, 2022
1 parent 24d6d42 commit 89dabd5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import * as fs from 'fs';

function replaceCDN() {
return {
name: 'vite-replace-cdn',
closeBundle() {
const entryHTML = 'dist/index.html';
const CDNPath = "//cdn.jsdelivr.net/gh/ant-galaxy/oasis-engine.github.io@gh-pages/assets/";

let text = fs.readFileSync(entryHTML, {
encoding: 'utf8'
});

text = text.replace(/\/assets\//g, CDNPath);

fs.writeFileSync(entryHTML, text, {
encoding: 'utf8'
});
}
}
}

export default ({ mode }) => {
return defineConfig({
Expand All @@ -8,7 +29,10 @@ export default ({ mode }) => {
host: "0.0.0.0",
port: 3333
},
plugins: [react()],
plugins: [
react(),
replaceCDN()
],
define: {
"process.env.NODE_ENV": `"${mode}"`,
},
Expand All @@ -22,7 +46,7 @@ export default ({ mode }) => {
'@oasis-engine/spine': ['@oasis-engine/spine'],
'@babel/standalone': ['@babel/standalone']
}
}
},
}
}
})
Expand Down

0 comments on commit 89dabd5

Please sign in to comment.