-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
149 lines (130 loc) · 3.36 KB
/
webpack.config.js
File metadata and controls
149 lines (130 loc) · 3.36 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const webpack = require('webpack');
const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const ip = require('ip');
const environment = process.env.NODE_ENV || 'development';
const url = process.env.URL || ip.address() || 'localhost';
const port = process.env.PORT || '80';
const https = process.env.HTTPS || 'false';
const isProd = environment === 'production';
console.log(
`[${environment}] Building app for http${https === 'true' ? 's' : ''}://${url}:${port}`,
);
const config = [
{
name: 'client',
context: __dirname + '/src/client/',
entry: {
robocop: './main.ts',
},
output: {
path: __dirname + '/dist/client',
// publicPath: "/assets/",
filename: '[name].bundle.js',
},
devtool: 'source-map',
mode: environment,
devServer: {
port: 8080,
host: url,
stats: 'errors-only',
open: true,
public: `${url}:${port}`,
hot: true,
contentBase: ['./dist/client'],
watchContentBase: true,
},
plugins: [
new HtmlWebpackPlugin({
title: 'Custom template',
template: 'index.html',
hash: isProd,
}),
new TsConfigPathsPlugin({ configFileName: 'tsconfig.json' }),
new webpack.DefinePlugin({
'process.env': {
URL: JSON.stringify(url),
NODE_ENV: JSON.stringify(environment),
HTTPS: JSON.stringify(https),
},
}),
],
module: {
rules: [
{
test: /\.(png|svg|jpg|gif|fbx)$/,
use: ['file-loader'],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.scss$/,
use: [
'style-loader', // creates style nodes from JS strings
'css-loader', // translates CSS into CommonJS
'postcss-loader',
'sass-loader', // compiles Sass to CSS, using Node Sass by default
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
},
{
name: 'server',
context: __dirname + '/src/server/',
entry: {
robocop: './main.ts',
},
output: {
path: __dirname + '/dist/server',
filename: '[name].bundle.js',
libraryTarget: 'commonjs',
},
mode: environment,
module: {
rules: [
{
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader'],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
target: 'node',
externals: [/^(?!\.|\/).+/i],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
devtool: 'cheap-module-source-map',
plugins: [new TsConfigPathsPlugin({ configFileName: 'tsconfig.json' }), new CheckerPlugin()],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false,
keep_classnames: true,
keep_fnames: true,
output: {
comments: false,
},
},
}),
],
},
},
];
module.exports = config;