-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
90 lines (80 loc) · 2.5 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
85
86
87
88
89
90
const path = require('path');
const webpack = require('webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const dotenv = require('dotenv');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = env => {
const environment = env.ENVIRONMENT;
// Define the environment file path
const envPath = path.join(__dirname, `./config/.env.${environment}`);
// Start DotEnv
const envVariables = dotenv.config({ path: envPath }).parsed || process.env;
// Convert Environment Variables -> Object
const envKeys = Object.keys(envVariables).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(envVariables[next]);
return prev;
}, {});
// Returns the Webpack Object
return {
entry: {
app: './src/index.tsx',
},
output: {
filename: 'bundle.js',
publicPath: '/',
path: path.join(__dirname, './dist'),
},
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
// Dev server options
devServer: {
contentBase: path.join(__dirname, './dist'),
port: 4200,
inline: true,
hot: true,
historyApiFallback: true,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'react-dom': '@hot-loader/react-dom',
'@': path.join(__dirname, './src'),
},
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheDirectory: true, babelrc: true },
},
},
{ test: /\.css$/, loader: 'style-loader' },
{ test: /\.css$/, loader: 'css-loader' },
{
test: /\.(jp?g|png|gif|svg|ico)$/i,
use: [{ loader: 'file-loader', options: { outputPath: 'assets/' } }],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin(envKeys),
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, './public', 'index.html'),
}),
new CopyPlugin({
patterns: [
{ from: './public/reset.css', to: './reset.css' },
// { from: './public/favicon-16x16.png', to: './favicon-16x16.png' },
// { from: './public/favicon-32x32.png', to: './favicon-32x32.png' },
],
}),
],
};
};