Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit 9123915

Browse files
authored
Updated webpack-config (#409)
* Updated webpack config * Removed web polyfills * Udpated index.html style * Use primaryColor for msapplication navbutton-color * Moved WebpackDeepScopeAnalysisPlugin to common * Removed vendoring * Added support for `.otf` fonts * Removed custom optimization in favor of webpack defaults * Removed terser * Update yarn.lock
1 parent ed9d9f6 commit 9123915

File tree

6 files changed

+32
-776
lines changed

6 files changed

+32
-776
lines changed

packages/webpack-config/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"@babel/core": "^7.0.0",
1111
"@babel/polyfill": "^7.2.5",
1212
"babel-loader": "^8.0.5",
13-
"babel-preset-expo": "^5.0.0",
1413
"brotli-webpack-plugin": "^1.1.0",
1514
"case-sensitive-paths-webpack-plugin": "^2.2.0",
1615
"clean-webpack-plugin": "^1.0.1",
@@ -24,7 +23,6 @@
2423
"pnp-webpack-plugin": "^1.2.1",
2524
"progress-bar-webpack-plugin": "^1.12.1",
2625
"react-dev-utils": "^7.0.3",
27-
"terser-webpack-plugin": "^1.2.2",
2826
"url-loader": "^1.1.2",
2927
"webpack": "4.24.0",
3028
"webpack-bundle-analyzer": "^3.0.4",

packages/webpack-config/web-default/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
body,
1919
#main {
2020
height: 100%;
21+
margin: 0px;
22+
padding: 0px;
2123
}
2224
#main {
2325
display: flex;
@@ -31,10 +33,12 @@
3133
<div id="main"></div>
3234

3335
<script>
34-
if ('serviceWorker' in navigator)
36+
if ('serviceWorker' in navigator) {
3537
window.addEventListener('load', function() {
3638
navigator.serviceWorker.register('/service-worker.js');
3739
});
40+
}
3841
</script>
42+
3943
</body>
4044
</html>

packages/webpack-config/webpack/createIndexHTMLFromAppJSON.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ function createIndexHTMLFromAppJSON(locations) {
55

66
const { expo: expoManifest = {} } = nativeAppManifest;
77

8+
const color = expoManifest.primaryColor || '#000000';
9+
810
const metaTags = {
911
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no',
1012
description: expoManifest.description || 'A Neat Expo App',
11-
'theme-color': expoManifest.primaryColor || '#000000',
13+
'theme-color': color,
1214
'apple-mobile-web-app-capable': 'yes',
1315
// default, black, black-translucent
1416
'apple-mobile-web-app-status-bar-style': 'default',
1517
'apple-mobile-web-app-title': expoManifest.name,
1618
'application-name': expoManifest.name,
1719
// Windows
18-
'msapplication-navbutton-color': '',
20+
'msapplication-navbutton-color': color,
1921
'msapplication-TileColor': '',
2022
'msapplication-TileImage': '',
2123
};

packages/webpack-config/webpack/webpack.common.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
55
const ManifestPlugin = require('webpack-manifest-plugin');
66
const WorkboxPlugin = require('workbox-webpack-plugin');
77
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
8+
const WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin').default;
89
const getLocations = require('./webpackLocations');
910
const createIndexHTMLFromAppJSON = require('./createIndexHTMLFromAppJSON');
1011
const createClientEnvironment = require('./createClientEnvironment');
@@ -83,7 +84,7 @@ module.exports = function(env) {
8384
const nativeAppManifest = require(locations.appJson);
8485

8586
const ttfLoaderConfiguration = {
86-
test: /\.ttf$/,
87+
test: /\.(ttf|otf)$/,
8788
use: [
8889
{
8990
loader: 'url-loader',
@@ -106,24 +107,7 @@ module.exports = function(env) {
106107
exclude: locations.template.folder,
107108
};
108109

109-
// This method intercepts modules being referenced in react-native
110-
// and redirects them to web friendly versions in expo.
111-
function getWebModule(initialRoot, moduleName) {
112-
return function(res) {
113-
if (res.context.includes('node_modules/react-native/')) {
114-
res.request = locations.includeModule(initialRoot + moduleName);
115-
}
116-
};
117-
}
118-
119-
function useWebModule(modulePathToHiJack, redirectPath, initialRoot = 'expo/build/web/') {
120-
return new webpack.NormalModuleReplacementPlugin(
121-
new RegExp(modulePathToHiJack),
122-
getWebModule(initialRoot, redirectPath)
123-
);
124-
}
125-
126-
const publicPath = '/';
110+
const publicPath = ''.replace(/\/$/, '');
127111

128112
return {
129113
context: __dirname,
@@ -160,13 +144,9 @@ module.exports = function(env) {
160144
fileName: 'asset-manifest.json',
161145
publicPath,
162146
}),
163-
164147
new webpack.DefinePlugin(clientEnv),
165-
166-
useWebModule('Performance/Systrace', 'Performance/Systrace'),
167-
useWebModule('RCTNetworking', 'Network/RCTNetworking'),
168-
useWebModule('Platform', 'Utilities/Platform'),
169-
useWebModule('HMRLoadingView', 'Utilities/HMRLoadingView'),
148+
// Remove unused import/exports
149+
new WebpackDeepScopeAnalysisPlugin(),
170150

171151
new WorkboxPlugin.GenerateSW({
172152
skipWaiting: true,

packages/webpack-config/webpack/webpack.prod.js

Lines changed: 11 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ const merge = require('webpack-merge');
22
const CleanWebpackPlugin = require('clean-webpack-plugin');
33
const CompressionPlugin = require('compression-webpack-plugin');
44
const CopyWebpackPlugin = require('copy-webpack-plugin');
5-
const TerserPlugin = require('terser-webpack-plugin');
65
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
76
const BrotliPlugin = require('brotli-webpack-plugin');
8-
const WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin').default;
97

108
const common = require('./webpack.common.js');
119
const getLocations = require('./webpackLocations');
@@ -24,131 +22,45 @@ module.exports = function(env = {}) {
2422
return merge(common(env), {
2523
mode: 'production',
2624
entry: {
27-
vendor: ['react', 'react-native-web'],
2825
app: appEntry,
2926
},
3027
devtool: 'source-map',
3128
plugins: [
32-
/** Delete the build folder */
29+
// Delete the build folder
3330
new CleanWebpackPlugin([locations.production.folder], {
3431
root: locations.root,
3532
verbose: true,
3633
dry: false,
3734
}),
38-
/** Remove unused import/exports */
39-
new WebpackDeepScopeAnalysisPlugin(),
35+
36+
new CopyWebpackPlugin([
37+
{
38+
from: locations.template.folder,
39+
to: locations.production.folder,
40+
ignore: 'index.html',
41+
},
42+
]),
4043

4144
new MiniCssExtractPlugin({
4245
filename: 'static/css/[contenthash].css',
4346
chunkFilename: 'static/css/[contenthash].chunk.css',
4447
}),
4548

46-
/** GZIP files */
49+
// GZIP files
4750
new CompressionPlugin({
4851
test: /\.(js|css)$/,
4952
filename: '[path].gz[query]',
5053
algorithm: 'gzip',
5154
threshold: 1024,
5255
minRatio: 0.8,
5356
}),
54-
/** secondary compression for platforms that load .br */
57+
// secondary compression for platforms that load .br
5558
new BrotliPlugin({
5659
asset: '[path].br[query]',
5760
test: /\.(js|css)$/,
5861
threshold: 1024,
5962
minRatio: 0.8,
6063
}),
61-
62-
/** Copy the PWA manifest.json and the caching policy serve.json from the template folder to the build folder */
63-
new CopyWebpackPlugin([
64-
{
65-
from: locations.template.manifest,
66-
to: locations.production.manifest,
67-
},
68-
{
69-
from: locations.template.serveJson,
70-
to: locations.production.serveJson,
71-
},
72-
]),
7364
],
74-
optimization: {
75-
usedExports: true,
76-
concatenateModules: true,
77-
occurrenceOrder: true,
78-
minimize: true,
79-
minimizer: [
80-
new TerserPlugin({
81-
cache: true,
82-
sourceMap: true,
83-
parallel: true,
84-
extractComments: 'all',
85-
terserOptions: {
86-
warnings: false,
87-
parse: {
88-
ecma: 8,
89-
},
90-
compress: {
91-
ecma: 5,
92-
warnings: false,
93-
comparisons: false,
94-
inline: 2,
95-
},
96-
mangle: {
97-
safari10: true,
98-
},
99-
output: {
100-
ecma: 5,
101-
comments: false,
102-
ascii_only: true,
103-
},
104-
module: false,
105-
toplevel: false,
106-
nameCache: null,
107-
ie8: false,
108-
keep_classnames: undefined,
109-
keep_fnames: false,
110-
},
111-
}),
112-
],
113-
splitChunks: {
114-
chunks: 'all',
115-
maxInitialRequests: Infinity,
116-
maxAsyncRequests: 5,
117-
minSize: 0,
118-
maxSize: 0,
119-
minChunks: Infinity,
120-
automaticNameDelimiter: '~',
121-
name: true,
122-
cacheGroups: {
123-
vendor: {
124-
chunks: 'all',
125-
priority: -10,
126-
test: /[\\/]node_modules[\\/]/,
127-
// name of the chunk
128-
name(module) {
129-
// get the name. E.g. node_modules/packageName/not/this/part.js
130-
// or node_modules/packageName
131-
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
132-
133-
// npm package names are URL-safe, but some servers don't like @ symbols
134-
return `npm.${packageName.replace('@', '')}`;
135-
},
136-
},
137-
default: {
138-
minChunks: 2,
139-
priority: -20,
140-
reuseExistingChunk: true,
141-
},
142-
commons: {
143-
name: 'commons',
144-
chunks: 'initial',
145-
minChunks: 2,
146-
priority: 10,
147-
reuseExistingChunk: true,
148-
enforce: true,
149-
},
150-
},
151-
},
152-
},
15365
});
15466
};

0 commit comments

Comments
 (0)