forked from BoostIO/BoostNote-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mobile.config.ts
164 lines (148 loc) · 4.25 KB
/
webpack.mobile.config.ts
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
161
162
163
164
import path from 'path'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import express from 'express'
import ErrorOverlayPlugin from 'error-overlay-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import packageJson from './package.json'
const devServerPort = 3000
const target = process.env.TARGET === 'ios' ? 'ios' : 'android'
module.exports = (env, argv) => {
const config = {
entry: [
'./src/mobile/index.tsx',
// the entry point of our app
],
output: {
filename: 'bundle.js',
path:
target === 'ios'
? path.resolve(__dirname, 'ios/BoostNote/BoostNote/compiled')
: path.resolve(__dirname, 'android/app/src/main/assets/compiled'),
},
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
loader: 'url-loader',
options: {
limit: 8192,
},
},
{
test: /\.tsx?$/,
use: [{ loader: 'ts-loader', options: { transpileOnly: true } }],
exclude: /node_modules/,
},
{
test: /\.md$/,
use: [
{
loader: 'raw-loader',
},
],
},
],
},
plugins: [
new webpack.NamedModulesPlugin(),
// prints more readable module names in the browser console on HMR updates
new webpack.NoEmitOnErrorsPlugin(),
// do not emit compiled assets that include errors
new HtmlWebpackPlugin({
template:
argv.mode === 'development'
? 'mobile-dev.html'
: target === 'ios'
? 'ios.html'
: 'android.html',
}),
new ErrorOverlayPlugin(),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(packageJson.version),
}),
new webpack.EnvironmentPlugin([
'NODE_ENV',
'MOBILE_AMPLIFY_AUTH_IDENTITY_POOL_ID',
'MOBILE_AMPLIFY_AUTH_REGION',
'MOBILE_AMPLIFY_PINPOINT_APPID',
'MOBILE_AMPLIFY_PINPOINT_REGION',
'BOOST_NOTE_BASE_URL',
'TARGET',
]),
new CopyPlugin([
{
from: path.join(__dirname, 'node_modules/codemirror/theme'),
to: 'm/codemirror/theme',
},
]),
new CopyPlugin([
{
from: path.join(__dirname, 'static'),
to: 'm/static',
},
]),
],
devServer: {
host: 'localhost',
port: devServerPort,
historyApiFallback: {
index: '/m',
},
// respond to 404s with index.html
hot: true,
// enable HMR on the server
before: function (app, server) {
app.use(
'/m/codemirror/mode',
express.static(path.join(__dirname, 'node_modules/codemirror/mode'))
)
app.use(
'/m/codemirror/addon',
express.static(path.join(__dirname, 'node_modules/codemirror/addon'))
)
app.use(
'/m/codemirror/theme',
express.static(path.join(__dirname, 'node_modules/codemirror/theme'))
)
app.use('/m/static', express.static(path.join(__dirname, 'static')))
},
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
node: {
fs: 'empty',
},
}
if (argv.mode === 'development') {
config.plugins.unshift(new webpack.HotModuleReplacementPlugin())
config.entry.unshift(
'react-hot-loader/patch',
`webpack-dev-server/client?http://localhost:${devServerPort}`,
'webpack/hot/only-dev-server'
)
;(config.output as any).publicPath = `http://localhost:${devServerPort}/m`
}
if (argv.mode === 'production') {
;(config as any).optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
keep_fnames: /Block|Value|Bool|BooleanLiteral|Null|NullLiteral|Literal|NumberLiteral|StringLiteral|RegexLiteral|Arr|Obj|Op|Parens/,
},
}),
],
}
;(config.output as any).publicPath =
target === 'ios' ? './' : 'file:///android_asset/compiled/'
}
return config
}