-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
133 lines (128 loc) · 3.92 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
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
const path = require('path'),
webpack = require('webpack'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
TerserPlugin = require('terser-webpack-plugin'),
CopyPlugin = require('copy-webpack-plugin')
const environment = process.env.NODE_ENV || 'development'
module.exports = {
mode: environment,
entry: {
app: ['./src/index.tsx', 'webpack-hot-middleware/client'],
// vendor: ['react', 'react-dom'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, './dist'),
publicPath: '/',
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
terserOptions: {
output: {
comments: false,
},
},
}),
],
},
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
devServer: {
contentBase: __dirname,
compress: true,
historyApiFallback: true,
proxy: {
'/api': {
target: 'http://localhost:3000',
secure: false,
changeOrigin: true,
pathRewrite: { '^/api': '' },
},
},
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.json'],
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
exclude: path.resolve(__dirname, 'functions'),
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
path.resolve(__dirname, 'functions'),
path.resolve(__dirname, 'node_modules', 'material-ui-next-pickers'),
],
},
{
test: /\.(jpg|png|svg|mp(3|4))$/,
loader: 'url-loader',
options: {
limit: 25000,
},
},
{
test: /\.scss$/,
use: [
'style-loader', // creates style nodes from JS strings
'css-loader', // translates CSS into CommonJS
'sass-loader', // compiles Sass to CSS, using Node Sass by default
],
},
],
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
react: 'React',
'react-dom': 'ReactDOM',
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.ejs'),
title: 'Dash',
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.EnvironmentPlugin({
NODE_ENV: environment, // use 'development' unless process.env.NODE_ENV is defined
DEBUG: false,
}),
new webpack.DefinePlugin({
MACRO: JSON.stringify(0),
DASH_API:
environment === 'development'
? JSON.stringify('http://localhost:3000')
: JSON.stringify('http://dash-api-19.herokuapp.com'),
GMAPS_API_KEY: JSON.stringify('AIzaSyBH47Nhu4cB_ynRUwmIXrQHxQIXrBUIp1Y'),
}),
new CopyPlugin([
{
from: path.resolve(
__dirname,
'node_modules',
'react',
'umd',
environment === 'development' ? 'react.development.js' : 'react.production.min.js',
),
to: path.resolve(__dirname, 'dist', 'react.js'),
},
{
from: path.resolve(__dirname, 'node_modules', 'react-dom', 'umd', environment === 'development' ? 'react-dom.development.js' : 'react-dom.production.min.js'),
to: path.resolve(__dirname, 'dist', 'react-dom.js'),
},
]),
],
}