Skip to content

Commit 8faaf46

Browse files
CharlieFRuanjingyi-zhao-01
authored andcommitted
[Fix][Vite] Fix string escape in index.js.map (mlc-ai#440)
This PR fixes `\"` issue in `index.js.map`, which breaks Vite deployment, follows the thread mlc-ai#414 This PR undoes the change in `cleanup-index-js.sh` to `index.js` in mlc-ai#420, and update `"` to `'` for `index.js.map`.
1 parent 518e0b2 commit 8faaf46

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cleanup-index-js.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ sed -e s/"const{createRequire:createRequire}=await import('module');"//g -i .bac
77
# Replace string "new (require('u' + 'rl').URL)('file:' + __filename).href" with "MLC_DUMMY_PATH"
88
# This is required for building nextJS projects -- its compile time would complain about `require()`
99
# See https://github.com/mlc-ai/web-llm/issues/383 and the fixing PR's description for more.
10-
sed -e s/"new (require('u' + 'rl').URL)('file:' + __filename).href"/"\\\"MLC_DUMMY_PATH\\\""/g -i .backup lib/index.js
11-
sed -e s/"new (require('u' + 'rl').URL)('file:' + __filename).href"/"\\\"MLC_DUMMY_PATH\\\""/g -i .backup lib/index.js.map
10+
sed -e s/"new (require('u' + 'rl').URL)('file:' + __filename).href"/"\"MLC_DUMMY_PATH\""/g -i .backup lib/index.js
11+
# Replace with \"MLC_DUMMY_PATH\"
12+
sed -e s/"new (require('u' + 'rl').URL)('file:' + __filename).href"/'\\\"MLC_DUMMY_PATH\\\"'/g -i .backup lib/index.js.map
1213

1314
# Replace "import require$$3 from 'perf_hooks';" with a string "const require$$3 = "MLC_DUMMY_REQUIRE_VAR""
1415
# This is to prevent `perf_hooks` not found error
1516
# For more see https://github.com/mlc-ai/web-llm/issues/258 and https://github.com/mlc-ai/web-llm/issues/127
1617
sed -e s/"import require\$\$3 from 'perf_hooks';"/"const require\$\$3 = \"MLC_DUMMY_REQUIRE_VAR\""/g -i .backup lib/index.js
17-
# Similarly replace `const performanceNode = require(\"perf_hooks\")` with `const performanceNode = "MLC_DUMMY_REQUIRE_VAR"`
18+
# Similarly replace `const performanceNode = require(\"perf_hooks\")` with `const performanceNode = \"MLC_DUMMY_REQUIRE_VAR\"`
1819
sed -e s/'require(\\\"perf_hooks\\\")'/'\\\"MLC_DUMMY_REQUIRE_VAR\\\"'/g -i .backup lib/index.js.map
1920

2021
# Cleanup backup files

0 commit comments

Comments
 (0)