forked from THEOplayer/react-native-theoplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
84 lines (76 loc) · 2.56 KB
/
webpack.config.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
const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const appDirectory = path.resolve(__dirname, '..');
// A folder for any stub components we need in case there is no counterpart for it on react-native-web.
const stubDirectory = path.resolve(appDirectory, '../src/internal/web/stub/');
const HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: path.resolve(appDirectory, './web/public/index.html'),
filename: 'index.html',
inject: 'body',
});
// This is needed for webpack to compile JavaScript.
// Many OSS React Native packages are not compiled to ES5 before being
// published. If you depend on uncompiled packages they may cause webpack build
// errors. To fix this webpack can be configured to compile to the necessary
// `node_module`.
const babelLoaderConfiguration = {
test: /\.tsx?$/,
exclude: ['/**/*.d.ts', '/**/node_modules/'],
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
// The 'metro-react-native-babel-preset' preset is recommended to match React Native's packager
presets: ['module:metro-react-native-babel-preset'],
// Re-write paths to import only the modules needed by the app
plugins: ['react-native-web'],
},
},
};
// This is needed for webpack to import static images in JavaScript files.
const imageLoaderConfiguration = {
test: /\.(gif|jpe?g|png|svg)$/,
use: {
loader: 'react-native-web-image-loader',
},
};
module.exports = {
entry: [
// load any web API polyfills
// path.resolve(appDirectory, 'polyfills-web.js'),
// your web-specific entry file
path.resolve(appDirectory, 'index.web.tsx'),
],
// configures where the build ends up
output: {
filename: 'bundle.web.js',
path: path.resolve(appDirectory, 'dist'),
},
module: {
rules: [babelLoaderConfiguration, imageLoaderConfiguration],
},
resolve: {
extensions: ['.web.js', '.web.ts', '.web.tsx', '.js', '.ts', '.tsx'],
alias: {
'react-native$': 'react-native-web',
'react-native-url-polyfill': 'url-polyfill',
'react-native-google-cast': path.resolve(stubDirectory, 'CastButtonStub'),
},
},
plugins: [HTMLWebpackPluginConfig],
devServer: {
// Tells dev-server to open the browser after server had been started.
open: true,
historyApiFallback: true,
static: [
{
directory: path.join(appDirectory, 'web/public'),
},
{
// This is needed to also serve the node_modules/theoplayer folder.
directory: path.join(appDirectory, '..'),
},
],
hot: true,
},
};