forked from OpenEnergyDashboard/OED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
76 lines (70 loc) · 1.99 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
const webpack = require('webpack');
const path = require('path');
const BUILD_DIR = path.resolve(__dirname, 'src/client/public/app');
const APP_DIR = path.resolve(__dirname, 'src/client/app');
const config = {
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
entry: {
application: APP_DIR + '/index.tsx',
},
cache: {
type: 'filesystem'
},
resolve: {
fallback: {
'buffer': require.resolve('buffer/'),
'assert': require.resolve('assert/'),
'stream': require.resolve('stream-browserify'),
'fs': false
},
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.css', '.ts', '.tsx', '.js', '.jsx', '.json']
},
// Ignore warnings about bundle size
performance: {
hints: false
},
module: {
rules: [
// All TypeScript ('.ts' or '.tsx') will be handled by 'awesome-typescript-loader'.
{ test: /\.[jt]sx?$/, exclude: /node_modules/, use: 'ts-loader' },
// CSS stylesheet loader.
{ test: /\.css$/, use: [
{loader: 'style-loader'},
{loader: 'css-loader'}
] },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: 'pre', test: /\.js$/, use:[{loader: 'source-map-loader'}] }
]
},
output: {
filename: 'bundle.js',
path: BUILD_DIR
},
plugins: [
new LodashModuleReplacementPlugin(),
new NodePolyfillPlugin()
]
};
if (process.env.NODE_ENV === 'production') {
config.plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new TerserPlugin({
terserOptions: {
sourceMap: true
}
})
);
}
module.exports = config;