-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.commons.js
160 lines (158 loc) · 5.24 KB
/
webpack.commons.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
154
155
156
157
158
159
160
/*
********************************************
Copyright © 2021 Agora Lab, Inc., all rights reserved.
AppBuilder and all associated components, source code, APIs, services, and
documentation (the “Materials”) are owned by Agora Lab, Inc. and its licensors.
The Materials may not be accessed, used, modified, or distributed for any
purpose without a license from Agora Lab, Inc. Use without a license or in
violation of any license terms and conditions (including use for any purpose
competitive to Agora Lab, Inc.’s business) is strictly prohibited. For more
information visit https://appbuilder.agora.io.
*********************************************
*/
/**
* Common Webpack configuration to be used across web and electron's renderer
* process
*/
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const isDevelopment = process.env.NODE_ENV === 'development';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const configVars = require('./configTransform');
const {
getCustomizationApiPath,
customizationDummyPath,
} = require('./customization.config');
const isElectron = ['linux', 'windows', 'mac'].includes(process.env.TARGET);
const isReactSdk = process.env.TARGET === 'rsdk';
const isWebSdk = process.env.TARGET === 'wsdk';
const isSdk = isReactSdk || isWebSdk;
module.exports = {
// Adds React Refresh webpack plugin for webpack dev server hmr
plugins: [
// Using html webpack plugin to utilize our index.html
!isSdk &&
new HtmlWebpackPlugin({
title: configVars['$config.APP_NAME'],
template: isElectron ? 'electron/index.html' : 'web/index.html',
}),
isDevelopment &&
!isSdk &&
new ReactRefreshWebpackPlugin({
overlay: false,
}),
].filter(Boolean),
resolve: {
alias: {
// Using react-native web to translate UI
'react-native$': 'react-native-web',
// Using rtm bridge to translate React Native RTM SDK calls to web SDK calls
'agora-react-native-rtm$': path.join(
__dirname,
'bridge/rtm/web/index.ts',
),
// Using rtc bridge to translate React Native RTC SDK calls to web SDK calls for web and linux
// Using rtc bridge to translate React Native RTC SDK calls to electron SDK calls for windows and mac
'react-native-agora$': path.join(__dirname, 'bridge/rtc/webNg/index.ts'),
'customization-api': path.join(__dirname, 'customization-api/index.ts'),
'customization-implementation': path.join(
__dirname,
'customization-implementation/index.ts',
),
customization: path.join(
__dirname,
isSdk ? customizationDummyPath : getCustomizationApiPath(),
),
'agora-react-native-rtm/lib/typescript/src': path.join(
__dirname,
'bridge/rtm/web/index.ts',
),
},
// Adds platform specific extensions and OS specific extensions
// .web.tsx works for web specific code
// .electron.tsx works for electron specific code
// .linux.tsx works for OS(linux) specific electron code
extensions: [
`.${process.env.TARGET}.tsx`,
`.${process.env.TARGET}.ts`,
isElectron && '.electron.tsx',
isElectron && '.electron.ts',
isSdk && '.sdk.ts',
isSdk && '.sdk.tsx',
isSdk && '.web.ts',
isSdk && '.web.tsx',
'.tsx',
'.ts',
'.jsx',
'.js',
'.node',
].filter(Boolean),
},
// Enable source maps during development
devtool: isDevelopment ? 'eval-cheap-module-source-map' : undefined,
module: {
rules: [
{
// Use babel to transpile all js, ts, jsx and tsx files
test: /\.[jt]sx?$/,
exclude: /node_modules/, // don't transpile the files under node_modules
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true, // enables caching in babel
configFile: false,
presets: [
'@babel/preset-react', // transforms tsx into normal ts
[
'@babel/preset-typescript', // transforms ts into js
{
allExtensions: true,
isTSX: true,
},
],
[
'@babel/preset-env', // smartly transforms js into es5-es6
{
targets: {
node: 'current',
},
},
],
],
plugins: [
// Adds support for class properties
['transform-define', configVars],
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-class-properties',
isDevelopment && !isSdk && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(wasm)$/i,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'wasm',
name: '[name].[ext]',
},
},
],
},
],
},
};