-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathwebpack.common.js
153 lines (141 loc) · 5.52 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const _ = require('underscore');
const path = require('path');
const {IgnorePlugin} = require('webpack');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const CustomVersionFilePlugin = require('./CustomVersionFilePlugin');
// Check for a --platform command line argument (default to 'web')
// If it is 'web', we want to ignore .desktop.js files, and if it is 'desktop', we want to ignore .website.js files.
const platformIndex = _.findIndex(process.argv, arg => arg === '--platform');
const platform = (platformIndex > 0) ? process.argv[platformIndex + 1] : 'web';
const platformExclude = platform === 'web' ? new RegExp(/\.desktop\.js$/) : new RegExp(/\.website\.js$/);
const includeModules = [
'react-native-animatable',
'react-native-reanimated',
'react-native-picker-select',
'react-native-web',
'@react-native-picker',
'react-native-modal',
'react-native-onyx',
'react-native-gesture-handler',
'react-native-flipper',
'react-native-google-places-autocomplete',
].join('|');
const webpackConfig = {
entry: {
app: './index.js',
},
output: {
filename: '[name]-[hash].bundle.js',
path: path.resolve(__dirname, '../../dist'),
publicPath: '/',
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'web/index.html',
filename: 'index.html',
usePolyfillIO: platform === 'web',
}),
// Copies favicons into the dist/ folder to use for unread status
new CopyPlugin({
patterns: [
{from: 'web/favicon.png'},
{from: 'web/favicon-unread.png'},
{from: 'web/og-preview-image.png'},
{from: 'assets/css', to: 'css'},
{from: 'node_modules/react-pdf/dist/esm/Page/AnnotationLayer.css', to: 'css/AnnotationLayer.css'},
{from: 'assets/images/shadow.png', to: 'images/shadow.png'},
{from: '.well-known/apple-app-site-association', to: '.well-known/apple-app-site-association'},
// These files are copied over as per instructions here
// https://github.com/wojtekmaj/react-pdf#copying-cmaps
{from: 'node_modules/pdfjs-dist/cmaps/', to: 'cmaps/'},
],
}),
new IgnorePlugin(/^\.\/locale$/, /moment$/),
new CustomVersionFilePlugin(),
],
module: {
rules: [
// Transpiles and lints all the JS
{
test: /\.js$/,
loader: 'babel-loader',
/**
* Exclude node_modules except any packages we need to convert for rendering HTML because they import
* "react-native" internally and use JSX which we need to convert to JS for the browser.
*
* You'll need to add anything in here that needs the alias for "react-native" -> "react-native-web"
* You can remove something from this list if it doesn't use "react-native" as an import and it doesn't
* use JSX/JS that needs to be transformed by babel.
*/
exclude: [
new RegExp(`node_modules/(?!(${includeModules})/).*|.native.js$`),
platformExclude,
],
},
{
test: /\.js$/,
loader: 'eslint-loader',
exclude: [
/node_modules|\.native\.js$/,
platformExclude,
],
options: {
cache: false,
emitWarning: true,
configFile: path.resolve(__dirname, '../../.eslintrc.js'),
},
},
// Rule for react-native-web-webview
{
test: /postMock.html$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
},
// Gives the ability to load local images
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
// Load svg images
{
test: /\.svg$/,
exclude: /node_modules/,
use: [
{
loader: '@svgr/webpack',
},
],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: {
alias: {
'react-native-config': 'react-web-config',
'react-native$': 'react-native-web',
},
// React Native libraries may have web-specific module implementations that appear with the extension `.web.js`
// without this, web will try to use native implementations and break in not very obvious ways.
// This is also why we have to use .website.js for our own web-specific files...
// Because desktop also relies on "web-specific" module implementations
extensions: ['.web.js', (platform === 'web') ? '.website.js' : '.desktop.js', '.js', '.jsx'],
},
};
if (platform === 'desktop') {
webpackConfig.target = 'electron-renderer';
}
module.exports = webpackConfig;