-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (76 loc) · 2.26 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
// eslint-disable-next-line @typescript-eslint/no-var-requires
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackManifestPlugin = require('webpack-manifest-plugin');
const dotenv = require('dotenv');
/**
* Load env file and parse config, to be used when building the app
* @returns {webpack.DefinePlugin}
*/
const setEnvVars = () => {
const env = dotenv.config({
path: './www/.env'
}).parsed;
// loop over the keys and place them in the process.env namespace
const keys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
return new webpack.DefinePlugin(keys);
};
module.exports = {
entry: {
main: './www/src/index.tsx'
},
module: {
rules: [
{
test: /\.ts(x|)?$/,
use: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.[s|]css$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader'
}, {
loader: 'sass-loader',
options: {
implementation: require('dart-sass')
}
}]
}, {
test: /\.(png|svg|jpg|jpeg|gif|ico|woff2?)$/,
exclude: /node_modules/,
use: ['file-loader?name=[name].[ext]'] // ?name=[name].[ext] is only necessary to preserve the original file name
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx']
},
plugins: [
new HtmlWebpackPlugin({
template: './www/public/index.html',
favicon: path.resolve(__dirname, 'public', 'favicon.ico')
}),
new WebpackManifestPlugin(),
setEnvVars()
],
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, 'www', 'public'),
publicPath: '/'
},
mode: 'development',
devServer: {
host: 'localhost',
port: 3000,
open: true,
historyApiFallback: true,
publicPath: '/',
hot: true
}
};