Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CRA to Vite Migration Script
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zandor Smith
CRA to Vite Migration Script
Commits
e4b90599
Verified
Commit
e4b90599
authored
11 months ago
by
Zandor Smith
Browse files
Options
Downloads
Patches
Plain Diff
Set host in script 8.
parent
8a3085ca
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/steps/08-create-vite-config.mjs
+23
-0
23 additions, 0 deletions
src/steps/08-create-vite-config.mjs
with
23 additions
and
0 deletions
src/steps/08-create-vite-config.mjs
+
23
−
0
View file @
e4b90599
...
...
@@ -40,6 +40,29 @@ async function step08CreateViteConfig() {
fileContent
=
fileContent
.
replace
(
"
<PROXY_SOURCE>
"
,
proxySource
);
fileContent
=
fileContent
.
replace
(
"
<PROXY_TARGET>
"
,
proxyTarget
);
const
packageJsonPath
=
"
./package.json
"
;
const
packageJsonContent
=
fs
.
readFileSync
(
packageJsonPath
,
"
utf8
"
);
const
packageJson
=
JSON
.
parse
(
packageJsonContent
);
if
(
packageJson
.
scripts
?.
start
?.
includes
(
"
HOST=
"
))
{
const
startScript
=
packageJson
.
scripts
.
start
;
const
startScriptParts
=
startScript
.
split
(
"
"
);
const
hostIndex
=
startScriptParts
.
findIndex
(
part
=>
part
.
includes
(
"
HOST=
"
));
if
(
hostIndex
===
-
1
)
{
throw
new
Error
(
"
HOST= not found in start script
"
);
}
const
host
=
startScriptParts
[
hostIndex
].
replace
(
"
HOST=
"
,
""
);
fileContent
=
fileContent
.
replace
(
"
<HOST>
"
,
host
);
}
else
{
// Remove line in vite config with host: "<HOST>"
const
viteConfigLines
=
fileContent
.
split
(
"
\n
"
);
const
hostLineIndex
=
viteConfigLines
.
findIndex
(
line
=>
line
.
includes
(
"
host:
"
));
if
(
hostLineIndex
===
-
1
)
{
throw
new
Error
(
"
host: not found in vite config
"
);
}
viteConfigLines
.
splice
(
hostLineIndex
,
1
);
fileContent
=
viteConfigLines
.
join
(
"
\n
"
);
}
fs
.
writeFileSync
(
targetPath
,
fileContent
);
console
.
log
(
"
vite.config.ts created
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment