-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e98687
commit feb8645
Showing
28 changed files
with
459 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,5 @@ dist-ssr | |
.idea | ||
|
||
# compiled | ||
utils/core/hmr-core/**/*.js | ||
utils/core/**/*.js | ||
public/manifest.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
react-app/utils/core/hmr-core/plugins/custom-dynamic-import.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
react-app/utils/core/hmr-core/log.ts → react-app/utils/core/log.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { PluginOption } from 'vite'; | ||
|
||
export default function customDynamicImport(): PluginOption { | ||
return { | ||
name: 'custom-dynamic-import', | ||
renderDynamicImport({ moduleId }) { | ||
if (!moduleId.includes('node_modules') && process.env.__FIREFOX__) { | ||
return { | ||
left: `import(browser.runtime.getURL('./') + `, | ||
right: ".split('../').join(''));", | ||
}; | ||
} | ||
return { | ||
left: 'import(', | ||
right: ')', | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as process from 'process'; | ||
import url from 'url'; | ||
import type { PluginOption } from 'vite'; | ||
import colorLog from '../log'; | ||
import ManifestParser from '../manifest-parser'; | ||
|
||
const { resolve } = path; | ||
|
||
const rootDir = resolve(__dirname, '../../..'); | ||
const distDir = resolve(rootDir, 'dist'); | ||
const manifestFile = resolve(rootDir, 'manifest.js'); | ||
|
||
const getManifestWithCacheBurst = (): Promise<{ default: chrome.runtime.ManifestV3 }> => { | ||
const withCacheBurst = (path: string) => `${path}?${Date.now().toString()}`; | ||
/** | ||
* In Windows, import() doesn't work without file:// protocol. | ||
* So, we need to convert path to file:// protocol. (url.pathToFileURL) | ||
*/ | ||
if (process.platform === 'win32') { | ||
return import(withCacheBurst(url.pathToFileURL(manifestFile).href)); | ||
} | ||
return import(withCacheBurst(manifestFile)); | ||
}; | ||
|
||
export default function makeManifest(): PluginOption { | ||
function makeManifest(manifest: chrome.runtime.ManifestV3, to: string) { | ||
if (!fs.existsSync(to)) { | ||
fs.mkdirSync(to); | ||
} | ||
const manifestPath = resolve(to, 'manifest.json'); | ||
|
||
fs.writeFileSync(manifestPath, ManifestParser.convertManifestToString(manifest)); | ||
|
||
colorLog(`Manifest file copy complete: ${manifestPath}`, 'success'); | ||
} | ||
|
||
return { | ||
name: 'make-manifest', | ||
buildStart() { | ||
this.addWatchFile(manifestFile); | ||
}, | ||
async writeBundle() { | ||
const manifest = await getManifestWithCacheBurst(); | ||
makeManifest(manifest.default, distDir); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { PluginOption } from 'vite'; | ||
import { WebSocket } from 'ws'; | ||
import { LOCAL_RELOAD_SOCKET_URL } from '../reload/constant'; | ||
import MessageInterpreter from '../reload/interpreter'; | ||
|
||
export default function watchRebuild(): PluginOption { | ||
const ws = new WebSocket(LOCAL_RELOAD_SOCKET_URL); | ||
return { | ||
name: 'watch-rebuild', | ||
writeBundle() { | ||
/** | ||
* When the build is complete, send a message to the reload server. | ||
* The reload server will send a message to the client to reload or refresh the extension. | ||
*/ | ||
ws.send(MessageInterpreter.send({ type: 'build_complete' })); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const LOCAL_RELOAD_SOCKET_PORT = 8081; | ||
export const LOCAL_RELOAD_SOCKET_URL = `ws://localhost:${LOCAL_RELOAD_SOCKET_PORT}`; |
Oops, something went wrong.