-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.ts
100 lines (96 loc) · 3.15 KB
/
webpack.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
/* eslint-disable import/no-extraneous-dependencies */
import { Configuration, SourceMapDevToolPlugin, ProvidePlugin, NormalModuleReplacementPlugin, DefinePlugin } from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import * as dotenv from 'dotenv'
import * as path from 'path'
import 'webpack-dev-server'
dotenv.config({ path: '.env' })
const config: Configuration = {
mode: 'none',
entry: { app: path.join(__dirname, 'src', 'index.tsx') },
target: 'web',
devtool: 'inline-source-map',
devServer: {
static: { directory: path.join(__dirname, 'public') },
compress: true,
https: true,
hot: true,
historyApiFallback: true,
port: 8080,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': '*'
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: '/node_modules/'
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: '/'
},
{
test: /\.(css|scss)$/,
use: [ 'style-loader', 'css-loader' ]
},
{
test: /\.js$/,
enforce: 'pre',
use: [ 'source-map-loader' ]
},
{
test: /\.(jpe?g|gif|png|svg)$/i,
use: [
{
loader: 'file-loader',
options: { limit: 10000 }
}
]
}
]
},
ignoreWarnings: [ /Failed to parse source map/ ],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
publicPath: '/'
},
plugins: [
new HtmlWebpackPlugin({ template: path.join(__dirname, 'public', 'index.html') }),
new SourceMapDevToolPlugin({ filename: '[file].map' }),
new ProvidePlugin({ Buffer: [ 'buffer', 'Buffer' ] }),
new ProvidePlugin({ process: 'process/browser.js' }),
new DefinePlugin({ 'process.env': JSON.stringify(process.env) }),
new NormalModuleReplacementPlugin(/node:/, (resource) => {
const mod = resource.request.replace(/^node:/, '')
switch (mod) {
case 'crypto':
resource.request = 'crypto'
break
default:
throw new Error(`Not found ${mod}`)
}
})
],
resolve: {
extensions: [ '.ts', '.tsx', '.js' ],
alias: { process: 'process/browser.js' },
fallback: {
util: require.resolve('util/'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
assert: require.resolve('assert'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify'),
url: require.resolve('url')
}
}
}
// eslint-disable-next-line import/no-default-export
export default config