Skip to content

Commit f4c216b

Browse files
committed
prettier file, use modern code, and add prompt at the beginning
1 parent 9d7ead2 commit f4c216b

File tree

2 files changed

+166
-158
lines changed

2 files changed

+166
-158
lines changed

packages/react-scripts/config/webpack.config.watch.js

+74-78
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010
// @remove-on-eject-end
11-
"use strict"
12-
var autoprefixer = require('autoprefixer');
13-
var webpack = require('webpack');
14-
var HtmlWebpackPlugin = require('html-webpack-plugin');
15-
var ExtractTextPlugin = require('extract-text-webpack-plugin');
16-
var ManifestPlugin = require('webpack-manifest-plugin');
17-
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
18-
var paths = require('./paths');
19-
var getClientEnvironment = require('./env');
20-
var isProduction = require('react-dev-utils/isProduction');
11+
'use strict';
12+
const autoprefixer = require('autoprefixer');
13+
const webpack = require('webpack');
14+
const HtmlWebpackPlugin = require('html-webpack-plugin');
15+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
16+
const ManifestPlugin = require('webpack-manifest-plugin');
17+
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
18+
const paths = require('./paths');
19+
const getClientEnvironment = require('./env');
20+
const isProduction = require('react-dev-utils/isProduction');
2121

2222
// @remove-on-eject-begin
2323
// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
24-
var path = require('path');
24+
const path = require('path');
2525
// @remove-on-eject-end
2626

2727
// Webpack uses `publicPath` to determine where the app is being served from.
2828
// It requires a trailing slash, or the file assets will get an incorrect path.
29-
var publicPath = paths.servedPath;
29+
const publicPath = paths.servedPath;
3030
// Some apps do not use client-side routing with pushState.
3131
// For these, "homepage" can be set to "." to enable relative asset paths.
32-
var shouldUseRelativeAssetPaths = publicPath === './';
32+
const shouldUseRelativeAssetPaths = publicPath === './';
3333
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3434
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3535
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
36-
var publicUrl = publicPath.slice(0, -1);
36+
const publicUrl = publicPath.slice(0, -1);
3737
// Get environment variables to inject into our app.
38-
var env = getClientEnvironment(publicUrl);
38+
const env = getClientEnvironment(publicUrl);
3939

4040
// Fall back to development if not production
4141
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
@@ -72,11 +72,11 @@ module.exports = {
7272
// We don't currently advertise code splitting but Webpack supports it.
7373
// There's prefix in the filename to identify which NODE_ENV generated this build
7474
filename: 'static/js/' + process.env.NODE_ENV + '.[name].[chunkhash:8].js',
75-
chunkFilename: (
76-
'static/js/' + process.env.NODE_ENV + '.[name].[chunkhash:8].chunk.js'
77-
),
75+
chunkFilename: 'static/js/' +
76+
process.env.NODE_ENV +
77+
'.[name].[chunkhash:8].chunk.js',
7878
// We inferred the "public path" (such as / or /my-project) from homepage.
79-
publicPath: publicPath
79+
publicPath: publicPath,
8080
},
8181
resolve: {
8282
// This allows you to set a fallback for where Webpack should look for modules.
@@ -93,8 +93,8 @@ module.exports = {
9393
alias: {
9494
// Support React Native Web
9595
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
96-
'react-native': 'react-native-web'
97-
}
96+
'react-native': 'react-native-web',
97+
},
9898
},
9999
// @remove-on-eject-begin
100100
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
@@ -103,8 +103,8 @@ module.exports = {
103103
modules: [
104104
paths.ownNodeModules,
105105
// Lerna hoists everything, so we need to look in our app directory
106-
paths.appNodeModules
107-
]
106+
paths.appNodeModules,
107+
],
108108
},
109109
// @remove-on-eject-end
110110
// This part is essentially the same as production configuration, but it remove
@@ -126,13 +126,13 @@ module.exports = {
126126
// TODO: consider separate config for production,
127127
// e.g. to enable no-console and no-debugger only in production.
128128
configFile: path.join(__dirname, '../.eslintrc'),
129-
useEslintrc: false
129+
useEslintrc: false,
130130
},
131131
// @remove-on-eject-end
132-
loader: 'eslint-loader'
133-
}
132+
loader: 'eslint-loader',
133+
},
134134
],
135-
include: paths.appSrc
135+
include: paths.appSrc,
136136
},
137137
// ** ADDING/UPDATING LOADERS **
138138
// The "url" loader handles all assets unless explicitly excluded.
@@ -147,10 +147,10 @@ module.exports = {
147147
loader: 'url-loader',
148148
options: {
149149
limit: 10000,
150-
name: (
151-
'static/media/' + process.env.NODE_ENV + '.[name].[hash:8].[ext]'
152-
)
153-
}
150+
name: 'static/media/' +
151+
process.env.NODE_ENV +
152+
'.[name].[hash:8].[ext]',
153+
},
154154
},
155155
// Process JS with Babel.
156156
{
@@ -160,9 +160,8 @@ module.exports = {
160160
// @remove-on-eject-begin
161161
options: {
162162
babelrc: false,
163-
presets: [require.resolve('babel-preset-react-app')]
164-
}
165-
163+
presets: [require.resolve('babel-preset-react-app')],
164+
},
166165
// @remove-on-eject-end
167166
},
168167
// The notation here is somewhat confusing.
@@ -187,8 +186,8 @@ module.exports = {
187186
{
188187
loader: 'css-loader',
189188
options: {
190-
importLoaders: 1
191-
}
189+
importLoaders: 1,
190+
},
192191
},
193192
{
194193
loader: 'postcss-loader',
@@ -201,34 +200,33 @@ module.exports = {
201200
'>1%',
202201
'last 4 versions',
203202
'Firefox ESR',
204-
'not ie < 9' // React doesn't support IE8 anyway
205-
]
206-
})
203+
'not ie < 9', // React doesn't support IE8 anyway
204+
],
205+
}),
207206
];
208-
}
209-
}
210-
}
211-
]
207+
},
208+
},
209+
},
210+
],
212211
},
213212
extractTextPluginOptions
214213
)
215-
)
216-
214+
),
217215
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
218216
},
219217
// "file" loader for svg
220218
{
221219
test: /\.svg$/,
222220
loader: 'file-loader',
223221
options: {
224-
name: (
225-
'static/media/' + process.env.NODE_ENV + '.[name].[hash:8].[ext]'
226-
)
227-
}
228-
}
222+
name: 'static/media/' +
223+
process.env.NODE_ENV +
224+
'.[name].[hash:8].[ext]',
225+
},
226+
},
229227
// ** STOP ** Are you adding a new loader?
230228
// Remember to add the new extension(s) to the "url" loader exclusion list.
231-
]
229+
],
232230
},
233231
plugins: [
234232
// Makes some environment variables available in index.html.
@@ -241,23 +239,21 @@ module.exports = {
241239
new HtmlWebpackPlugin({
242240
inject: true,
243241
template: paths.appHtml,
244-
minify: (
245-
isProduction()
246-
? // Minify the code if in production.
247-
{
248-
removeComments: true,
249-
collapseWhitespace: true,
250-
removeRedundantAttributes: true,
251-
useShortDoctype: true,
252-
removeEmptyAttributes: true,
253-
removeStyleLinkTypeAttributes: true,
254-
keepClosingSlash: true,
255-
minifyJS: true,
256-
minifyCSS: true,
257-
minifyURLs: true
258-
}
259-
: false
260-
)
242+
minify: isProduction()
243+
? // Minify the code if in production.
244+
{
245+
removeComments: true,
246+
collapseWhitespace: true,
247+
removeRedundantAttributes: true,
248+
useShortDoctype: true,
249+
removeEmptyAttributes: true,
250+
removeStyleLinkTypeAttributes: true,
251+
keepClosingSlash: true,
252+
minifyJS: true,
253+
minifyCSS: true,
254+
minifyURLs: true,
255+
}
256+
: false,
261257
}),
262258
// Makes some environment variables available to the JS code, for example:
263259
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
@@ -269,35 +265,35 @@ module.exports = {
269265
? new webpack.optimize.UglifyJsPlugin({
270266
compress: {
271267
screw_ie8: true, // React doesn't support IE8
272-
warnings: false
268+
warnings: false,
273269
},
274270
mangle: {
275-
screw_ie8: true
271+
screw_ie8: true,
276272
},
277273
output: {
278274
comments: false,
279-
screw_ie8: true
275+
screw_ie8: true,
280276
},
281-
sourceMap: true
277+
sourceMap: true,
282278
})
283279
: false,
284280
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
285281
new ExtractTextPlugin({
286-
filename: cssFilename
282+
filename: cssFilename,
287283
}),
288284
// Generate a manifest file which contains a mapping of all asset filenames
289285
// to their corresponding output file so that tools can pick it up without
290286
// having to parse `index.html`.
291287
// We also read this file to delete stale files in build folder
292288
new ManifestPlugin({
293-
fileName: 'asset-manifest.json'
294-
})
289+
fileName: 'asset-manifest.json',
290+
}),
295291
].filter(Boolean), // remove falsy plugin on development
296292
// Some libraries import Node modules but don't use them in the browser.
297293
// Tell Webpack to provide empty mocks for them so importing them works.
298294
node: {
299295
fs: 'empty',
300296
net: 'empty',
301-
tls: 'empty'
302-
}
303-
};
297+
tls: 'empty',
298+
},
299+
};

0 commit comments

Comments
 (0)