Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
37009b1f
Commit
37009b1f
authored
8 years ago
by
Dan Abramov
Committed by
GitHub
8 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Attempt to reuse Chrome tab on OS X (#62)
Fixes
#38
parent
b941ad2d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scripts/eject.js
+9
-4
scripts/eject.js
scripts/openChrome.applescript
+45
-0
scripts/openChrome.applescript
scripts/start.js
+23
-1
scripts/start.js
with
77 additions
and
5 deletions
+77
-5
scripts/eject.js
+
9
-
4
View file @
37009b1f
...
@@ -46,7 +46,8 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
...
@@ -46,7 +46,8 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
path
.
join
(
'
config
'
,
'
webpack.config.dev.js
'
),
path
.
join
(
'
config
'
,
'
webpack.config.dev.js
'
),
path
.
join
(
'
config
'
,
'
webpack.config.prod.js
'
),
path
.
join
(
'
config
'
,
'
webpack.config.prod.js
'
),
path
.
join
(
'
scripts
'
,
'
build.js
'
),
path
.
join
(
'
scripts
'
,
'
build.js
'
),
path
.
join
(
'
scripts
'
,
'
start.js
'
)
path
.
join
(
'
scripts
'
,
'
start.js
'
),
path
.
join
(
'
scripts
'
,
'
openChrome.applescript
'
)
];
];
// Ensure that the host folder is clean and we won't override any files
// Ensure that the host folder is clean and we won't override any files
...
@@ -68,9 +69,13 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
...
@@ -68,9 +69,13 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
files
.
forEach
(
function
(
file
)
{
files
.
forEach
(
function
(
file
)
{
console
.
log
(
'
Copying
'
+
file
+
'
to
'
+
hostPath
);
console
.
log
(
'
Copying
'
+
file
+
'
to
'
+
hostPath
);
var
content
=
fs
.
readFileSync
(
path
.
join
(
selfPath
,
file
),
'
utf8
'
);
content
=
fs
// Remove license header
.
readFileSync
(
path
.
join
(
selfPath
,
file
),
'
utf8
'
)
content
=
content
.
replace
(
/^
\/\*\*(\*(?!\/)
|
[^
*
])
*
\*\/
/
,
''
).
trim
()
+
'
\n
'
;
// Remove license header from JS
.
replace
(
/^
\/\*\*(\*(?!\/)
|
[^
*
])
*
\*\/
/
,
''
)
// Remove license header from AppleScript
.
replace
(
/^--.*
\n
/gm
,
''
)
.
trim
()
+
'
\n
'
;
fs
.
writeFileSync
(
path
.
join
(
hostPath
,
file
),
content
);
fs
.
writeFileSync
(
path
.
join
(
hostPath
,
file
),
content
);
});
});
console
.
log
();
console
.
log
();
...
...
This diff is collapsed.
Click to expand it.
scripts/openChrome.applescript
0 → 100644
+
45
-
0
View file @
37009b1f
-- Copyright (c) 2015-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
on
run
argv
set
theURL
to
item
1
of
argv
tell
application
"Chrome"
if
(
count
every
window
)
=
0
then
make
new
window
end
if
-- Find a tab currently running the debugger
set
found
to
false
set
theTabIndex
to
-
1
repeat
with
theWindow
in
every
window
set
theTabIndex
to
0
repeat
with
theTab
in
every
tab
of
theWindow
set
theTabIndex
to
theTabIndex
+
1
if
theTab
's
URL
is
theURL
then
set
found
to
true
exit
repeat
end
if
end
repeat
if
found
then
exit
repeat
end
if
end
repeat
if
found
then
tell
theTab
to
reload
set
index
of
theWindow
to
1
set
theWindow
's
active
tab
index
to
theTabIndex
else
tell
window
1
activate
make
new
tab
with
properties
{
URL
:
theURL
}
end
tell
end
if
end
tell
end
run
This diff is collapsed.
Click to expand it.
scripts/start.js
+
23
-
1
View file @
37009b1f
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
process
.
env
.
NODE_ENV
=
'
development
'
;
process
.
env
.
NODE_ENV
=
'
development
'
;
var
path
=
require
(
'
path
'
);
var
chalk
=
require
(
'
chalk
'
);
var
chalk
=
require
(
'
chalk
'
);
var
webpack
=
require
(
'
webpack
'
);
var
webpack
=
require
(
'
webpack
'
);
var
WebpackDevServer
=
require
(
'
webpack-dev-server
'
);
var
WebpackDevServer
=
require
(
'
webpack-dev-server
'
);
...
@@ -117,6 +118,27 @@ compiler.plugin('done', function (stats) {
...
@@ -117,6 +118,27 @@ compiler.plugin('done', function (stats) {
}
}
});
});
function
openBrowser
()
{
if
(
process
.
platform
===
'
darwin
'
)
{
try
{
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync
(
'
ps cax | grep "Google Chrome"
'
);
execSync
(
'
osascript
'
+
path
.
resolve
(
__dirname
,
'
./openChrome.applescript
'
)
+
'
http://localhost:3000/
'
);
return
;
}
catch
(
err
)
{
// Ignore errors.
}
}
// Fallback to opn
// (It will always open new tab)
opn
(
'
http://localhost:3000/
'
);
}
new
WebpackDevServer
(
compiler
,
{
new
WebpackDevServer
(
compiler
,
{
historyApiFallback
:
true
,
historyApiFallback
:
true
,
hot
:
true
,
// Note: only CSS is currently hot reloaded
hot
:
true
,
// Note: only CSS is currently hot reloaded
...
@@ -128,5 +150,5 @@ new WebpackDevServer(compiler, {
...
@@ -128,5 +150,5 @@ new WebpackDevServer(compiler, {
}
}
console
.
log
(
'
Starting the development server...
'
);
console
.
log
(
'
Starting the development server...
'
);
op
n
(
'
http://localhost:3000/
'
);
op
enBrowser
(
);
});
});
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment