-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.ts
162 lines (158 loc) · 4.37 KB
/
webpack.config.ts
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
150
151
152
153
154
155
156
157
158
159
160
161
162
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as InlineManifestWebpackPlugin from 'inline-manifest-webpack-plugin';
import * as path from 'path';
import * as webpack from 'webpack';
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const SERVER_PORT = process.env.SERVER_PORT || 3001;
const SERVER_HOSTNAME = process.env.SERVER_HOSTNAME || 'localhost';
const config: webpack.Configuration = {
mode: 'development',
devtool: 'cheap-module-source-map',
entry: [
'webpack/hot/dev-server',
`webpack-dev-server/client?http://${SERVER_HOSTNAME}:${SERVER_PORT}`,
path.join(__dirname, 'src', 'index.tsx'),
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'assets/[name].js',
chunkFilename: 'assets/[name].js',
publicPath: '/',
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
AUTH0_CLIENT_ID: JSON.stringify(process.env.AUTH0_CLIENT_ID),
AUTH0_DOMAIN: JSON.stringify(process.env.AUTH0_DOMAIN),
GA_ID: JSON.stringify(process.env.GA_ID),
},
}),
new CopyWebpackPlugin({
patterns: [{
from: 'env.js',
to: 'assets/env.js',
transform: (content: Buffer, path: string) => {
return `
window.env = {
DEPLOY_ENV: ${JSON.stringify(process.env.DEPLOY_ENV)},
APP_VERSION: ${JSON.stringify(process.env.APP_VERSION)},
APP_SECRET: ${JSON.stringify(process.env.APP_SECRET)},
GA_ID: ${JSON.stringify(process.env.GA_ID)}
}
`;
},
}],
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en/),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: 'BuildPipeline | 603.nz',
template: path.join(__dirname, 'src', 'index.ejs'),
favicon: path.join(__dirname, 'src', 'favicon.ico'),
meta: {
description: 'AWS-powered serverless build, test and deploy pipeline ft. multiple environments',
},
minify: {
collapseWhitespace: true,
},
}),
new InlineManifestWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({
async: false,
}),
],
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
cacheGroups: {
default: false,
vendor: {
name: 'vendor',
chunks: 'all',
test: /[\\/]node_modules[\\/]/,
priority: 20,
},
utilities: {
test: /[\\/]node_modules[\\/](immutable|moment|react|react-dom|react-loading)[\\/]/,
name: 'utilities',
priority: 30,
},
common: {
name: 'async-common',
minChunks: 2,
chunks: 'async',
priority: 10,
reuseExistingChunk: true,
enforce: true,
},
},
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.json'],
modules: [
path.join(__dirname, 'src'),
path.join(__dirname, 'node_modules'),
],
},
module: {
rules: [
{
test: /\.tsx?$/,
enforce: 'pre',
include: path.join(__dirname, 'src'),
exclude: path.join(__dirname, 'node_modules'),
use: ['tslint-loader'],
},
{
test: /\.tsx?$/,
include: path.join(__dirname, 'src'),
use: [{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}],
},
{
test: /\.js$/,
use: ['source-map-loader'],
include: path.join(__dirname, 'src'),
enforce: 'pre',
},
{
test: /\.css?$/,
include: path.join(__dirname, 'src'),
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
localIdentName: '[path][name]__[local]--[hash:base64:5]',
},
},
},
],
},
{
test: /\.(jpe?g|png|gif|svg|ico)$/,
include: path.join(__dirname, 'src'),
use: [{
loader: 'url-loader',
options: {
limit: 10240,
esModule: false,
},
}],
},
],
},
};
export default config;