Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bkunyun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bkunyun
Commits
a09f6f8a
Commit
a09f6f8a
authored
Jun 10, 2022
by
吴永生#A02208
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: script修改build文件
parent
b75b9115
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
52 deletions
+52
-52
build.js
scripts/build.js
+52
-52
No files found.
scripts/build.js
View file @
a09f6f8a
'use strict'
;
"use strict"
;
// Do this as the first thing so that any code reading it knows the right env.
// Do this as the first thing so that any code reading it knows the right env.
process
.
env
.
BABEL_ENV
=
'production'
;
process
.
env
.
BABEL_ENV
=
"production"
;
process
.
env
.
NODE_ENV
=
'production'
;
process
.
env
.
NODE_ENV
=
"production"
;
// Makes the script crash on unhandled rejections instead of silently
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
// terminate the Node.js process with a non-zero exit code.
process
.
on
(
'unhandledRejection'
,
err
=>
{
process
.
on
(
"unhandledRejection"
,
(
err
)
=>
{
throw
err
;
throw
err
;
});
});
// Ensure environment variables are read.
// Ensure environment variables are read.
require
(
'../config/env'
);
require
(
"../config/env"
);
const
path
=
require
(
'path'
);
const
path
=
require
(
"path"
);
const
chalk
=
require
(
'react-dev-utils/chalk'
);
const
chalk
=
require
(
"react-dev-utils/chalk"
);
const
fs
=
require
(
'fs-extra'
);
const
fs
=
require
(
"fs-extra"
);
const
bfj
=
require
(
'bfj'
);
const
bfj
=
require
(
"bfj"
);
const
webpack
=
require
(
'webpack'
);
const
webpack
=
require
(
"webpack"
);
const
configFactory
=
require
(
'../config/webpack.config'
);
const
configFactory
=
require
(
"../config/webpack.config"
);
const
paths
=
require
(
'../config/paths'
);
const
paths
=
require
(
"../config/paths"
);
const
checkRequiredFiles
=
require
(
'react-dev-utils/checkRequiredFiles'
);
const
checkRequiredFiles
=
require
(
"react-dev-utils/checkRequiredFiles"
);
const
formatWebpackMessages
=
require
(
'react-dev-utils/formatWebpackMessages'
);
const
formatWebpackMessages
=
require
(
"react-dev-utils/formatWebpackMessages"
);
const
printHostingInstructions
=
require
(
'react-dev-utils/printHostingInstructions'
);
const
printHostingInstructions
=
require
(
"react-dev-utils/printHostingInstructions"
);
const
FileSizeReporter
=
require
(
'react-dev-utils/FileSizeReporter'
);
const
FileSizeReporter
=
require
(
"react-dev-utils/FileSizeReporter"
);
const
printBuildError
=
require
(
'react-dev-utils/printBuildError'
);
const
printBuildError
=
require
(
"react-dev-utils/printBuildError"
);
const
measureFileSizesBeforeBuild
=
const
measureFileSizesBeforeBuild
=
FileSizeReporter
.
measureFileSizesBeforeBuild
;
FileSizeReporter
.
measureFileSizesBeforeBuild
;
...
@@ -44,21 +44,21 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
...
@@ -44,21 +44,21 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
}
}
const
argv
=
process
.
argv
.
slice
(
2
);
const
argv
=
process
.
argv
.
slice
(
2
);
const
writeStatsJson
=
argv
.
indexOf
(
'--stats'
)
!==
-
1
;
const
writeStatsJson
=
argv
.
indexOf
(
"--stats"
)
!==
-
1
;
// Generate configuration
// Generate configuration
const
config
=
configFactory
(
'production'
);
const
config
=
configFactory
(
"production"
);
// We require that you explicitly set browsers and do not fall back to
// We require that you explicitly set browsers and do not fall back to
// browserslist defaults.
// browserslist defaults.
const
{
checkBrowsers
}
=
require
(
'react-dev-utils/browsersHelper'
);
const
{
checkBrowsers
}
=
require
(
"react-dev-utils/browsersHelper"
);
checkBrowsers
(
paths
.
appPath
,
isInteractive
)
checkBrowsers
(
paths
.
appPath
,
isInteractive
)
.
then
(()
=>
{
.
then
(()
=>
{
// First, read the current file sizes in build directory.
// First, read the current file sizes in build directory.
// This lets us display how much they changed later.
// This lets us display how much they changed later.
return
measureFileSizesBeforeBuild
(
paths
.
appBuild
);
return
measureFileSizesBeforeBuild
(
paths
.
appBuild
);
})
})
.
then
(
previousFileSizes
=>
{
.
then
(
(
previousFileSizes
)
=>
{
// Remove all content but keep the directory so that
// Remove all content but keep the directory so that
// if you're in it, you don't end up in Trash
// if you're in it, you don't end up in Trash
fs
.
emptyDirSync
(
paths
.
appBuild
);
fs
.
emptyDirSync
(
paths
.
appBuild
);
...
@@ -70,23 +70,23 @@ checkBrowsers(paths.appPath, isInteractive)
...
@@ -70,23 +70,23 @@ checkBrowsers(paths.appPath, isInteractive)
.
then
(
.
then
(
({
stats
,
previousFileSizes
,
warnings
})
=>
{
({
stats
,
previousFileSizes
,
warnings
})
=>
{
if
(
warnings
.
length
)
{
if
(
warnings
.
length
)
{
console
.
log
(
chalk
.
yellow
(
'Compiled with warnings.
\
n'
));
console
.
log
(
chalk
.
yellow
(
"Compiled with warnings.
\n
"
));
console
.
log
(
warnings
.
join
(
'
\
n
\
n'
));
console
.
log
(
warnings
.
join
(
"
\n\n
"
));
console
.
log
(
console
.
log
(
'
\
nSearch for the '
+
"
\n
Search for the "
+
chalk
.
underline
(
chalk
.
yellow
(
'keywords'
))
+
chalk
.
underline
(
chalk
.
yellow
(
"keywords"
))
+
' to learn more about each warning.'
" to learn more about each warning."
);
);
console
.
log
(
console
.
log
(
'To ignore, add '
+
"To ignore, add "
+
chalk
.
cyan
(
'// eslint-disable-next-line'
)
+
chalk
.
cyan
(
"// eslint-disable-next-line"
)
+
' to the line before.
\
n'
" to the line before.
\n
"
);
);
}
else
{
}
else
{
console
.
log
(
chalk
.
green
(
'Compiled successfully.
\
n'
));
console
.
log
(
chalk
.
green
(
"Compiled successfully.
\n
"
));
}
}
console
.
log
(
'File sizes after gzip:
\
n'
);
console
.
log
(
"File sizes after gzip:
\n
"
);
printFileSizesAfterBuild
(
printFileSizesAfterBuild
(
stats
,
stats
,
previousFileSizes
,
previousFileSizes
,
...
@@ -108,23 +108,23 @@ checkBrowsers(paths.appPath, isInteractive)
...
@@ -108,23 +108,23 @@ checkBrowsers(paths.appPath, isInteractive)
useYarn
useYarn
);
);
},
},
err
=>
{
(
err
)
=>
{
const
tscCompileOnError
=
process
.
env
.
TSC_COMPILE_ON_ERROR
===
'true'
;
const
tscCompileOnError
=
process
.
env
.
TSC_COMPILE_ON_ERROR
===
"true"
;
if
(
tscCompileOnError
)
{
if
(
tscCompileOnError
)
{
console
.
log
(
console
.
log
(
chalk
.
yellow
(
chalk
.
yellow
(
'Compiled with the following type errors (you may want to check these before deploying your app):
\
n'
"Compiled with the following type errors (you may want to check these before deploying your app):
\n
"
)
)
);
);
printBuildError
(
err
);
printBuildError
(
err
);
}
else
{
}
else
{
console
.
log
(
chalk
.
red
(
'Failed to compile.
\
n'
));
console
.
log
(
chalk
.
red
(
"Failed to compile.
\n
"
));
printBuildError
(
err
);
printBuildError
(
err
);
process
.
exit
(
1
);
process
.
exit
(
1
);
}
}
}
}
)
)
.
catch
(
err
=>
{
.
catch
(
(
err
)
=>
{
if
(
err
&&
err
.
message
)
{
if
(
err
&&
err
.
message
)
{
console
.
log
(
err
.
message
);
console
.
log
(
err
.
message
);
}
}
...
@@ -132,8 +132,8 @@ checkBrowsers(paths.appPath, isInteractive)
...
@@ -132,8 +132,8 @@ checkBrowsers(paths.appPath, isInteractive)
});
});
// Create the production build and print the deployment instructions.
// Create the production build and print the deployment instructions.
function
build
(
previousFileSizes
)
{
export
default
function
build
(
previousFileSizes
)
{
console
.
log
(
'Creating an optimized production build...'
);
console
.
log
(
"Creating an optimized production build..."
);
const
compiler
=
webpack
(
config
);
const
compiler
=
webpack
(
config
);
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -147,10 +147,10 @@ function build(previousFileSizes) {
...
@@ -147,10 +147,10 @@ function build(previousFileSizes) {
let
errMessage
=
err
.
message
;
let
errMessage
=
err
.
message
;
// Add additional information for postcss errors
// Add additional information for postcss errors
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
err
,
'postcssNode'
))
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
err
,
"postcssNode"
))
{
errMessage
+=
errMessage
+=
'
\
nCompileError: Begins at CSS selector '
+
"
\n
CompileError: Begins at CSS selector "
+
err
[
'postcssNode'
].
selector
;
err
[
"postcssNode"
].
selector
;
}
}
messages
=
formatWebpackMessages
({
messages
=
formatWebpackMessages
({
...
@@ -168,26 +168,26 @@ function build(previousFileSizes) {
...
@@ -168,26 +168,26 @@ function build(previousFileSizes) {
if
(
messages
.
errors
.
length
>
1
)
{
if
(
messages
.
errors
.
length
>
1
)
{
messages
.
errors
.
length
=
1
;
messages
.
errors
.
length
=
1
;
}
}
return
reject
(
new
Error
(
messages
.
errors
.
join
(
'
\
n
\
n'
)));
return
reject
(
new
Error
(
messages
.
errors
.
join
(
"
\n\n
"
)));
}
}
if
(
if
(
process
.
env
.
CI
&&
process
.
env
.
CI
&&
(
typeof
process
.
env
.
CI
!==
'string'
||
(
typeof
process
.
env
.
CI
!==
"string"
||
process
.
env
.
CI
.
toLowerCase
()
!==
'false'
)
&&
process
.
env
.
CI
.
toLowerCase
()
!==
"false"
)
&&
messages
.
warnings
.
length
messages
.
warnings
.
length
)
{
)
{
// Ignore sourcemap warnings in CI builds. See #8227 for more info.
// Ignore sourcemap warnings in CI builds. See #8227 for more info.
const
filteredWarnings
=
messages
.
warnings
.
filter
(
const
filteredWarnings
=
messages
.
warnings
.
filter
(
w
=>
!
/Failed to parse source map/
.
test
(
w
)
(
w
)
=>
!
/Failed to parse source map/
.
test
(
w
)
);
);
if
(
filteredWarnings
.
length
)
{
if
(
filteredWarnings
.
length
)
{
console
.
log
(
console
.
log
(
chalk
.
yellow
(
chalk
.
yellow
(
'
\
nTreating warnings as errors because process.env.CI = true.
\
n'
+
"
\n
Treating warnings as errors because process.env.CI = true.
\n
"
+
'Most CI servers set it automatically.
\
n'
"Most CI servers set it automatically.
\n
"
)
)
);
);
return
reject
(
new
Error
(
filteredWarnings
.
join
(
'
\
n
\
n'
)));
return
reject
(
new
Error
(
filteredWarnings
.
join
(
"
\n\n
"
)));
}
}
}
}
...
@@ -199,9 +199,9 @@ function build(previousFileSizes) {
...
@@ -199,9 +199,9 @@ function build(previousFileSizes) {
if
(
writeStatsJson
)
{
if
(
writeStatsJson
)
{
return
bfj
return
bfj
.
write
(
paths
.
appBuild
+
'/bundle-stats.json'
,
stats
.
toJson
())
.
write
(
paths
.
appBuild
+
"/bundle-stats.json"
,
stats
.
toJson
())
.
then
(()
=>
resolve
(
resolveArgs
))
.
then
(()
=>
resolve
(
resolveArgs
))
.
catch
(
error
=>
reject
(
new
Error
(
error
)));
.
catch
(
(
error
)
=>
reject
(
new
Error
(
error
)));
}
}
return
resolve
(
resolveArgs
);
return
resolve
(
resolveArgs
);
...
@@ -212,6 +212,6 @@ function build(previousFileSizes) {
...
@@ -212,6 +212,6 @@ function build(previousFileSizes) {
function
copyPublicFolder
()
{
function
copyPublicFolder
()
{
fs
.
copySync
(
paths
.
appPublic
,
paths
.
appBuild
,
{
fs
.
copySync
(
paths
.
appPublic
,
paths
.
appBuild
,
{
dereference
:
true
,
dereference
:
true
,
filter
:
file
=>
file
!==
paths
.
appHtml
,
filter
:
(
file
)
=>
file
!==
paths
.
appHtml
,
});
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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