forked from jsmith-sapient/spec-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
137 lines (127 loc) · 2.47 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
134
135
136
137
require('dotenv').config();
// native node modules
const path = require('path');
// 3rd-party
const wpMerge = require('webpack-merge');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const PwaManifest = require('webpack-pwa-manifest');
// app
const {
appPaths,
client,
htmlDocument,
pwaManifest,
} = require('./config');
const CONFIG = {
apiKey: process.env.OPEN_EXCHANGE_API_KEY,
env: process.env.NODE_ENV || 'development',
name: process.env.npm_package_name,
shortName: process.env.npm_package_shortName,
version: process.env.npm_package_version,
...client,
};
const isDev = CONFIG.env === 'development';
const envWebpackConfig = require(`./webpack.config.${CONFIG.env}`) || {};
const baseWebpackConfig = {
context: appPaths.src,
devtool: 'source-map', // 'inline-source-map'
entry: {
app: [
path.resolve(appPaths.client, 'index.tsx'),
],
},
mode: CONFIG.env,
module: {
rules: [
{
sideEffects: false,
},
{
test: /\.eot$|\.ttf$|\.gif$|\.jpe?g$|\.png$|\.svg$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[hash].[ext]',
},
},
]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/fontwoff',
},
},
],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
},
{
enforce: 'pre',
test: /\.js$/,
use: 'source-map-loader',
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
semanticUi: {
chunks: 'all',
name: 'semantic-ui',
priority: 1,
test: /semantic-ui/,
},
vendor: {
chunks: 'all',
name: 'vendor',
priority: 0,
test: /node_modules/,
},
},
},
},
output: {
filename: '[name].[hash].bundle.js',
path: appPaths.dist,
publicPath: '/',
},
plugins: [
new webpack.DefinePlugin({
CONFIG: JSON.stringify(CONFIG),
ENABLE_DEBUGGING: isDev,
}),
new HtmlWebpackPlugin(htmlDocument),
new PwaManifest(pwaManifest),
],
resolve: {
alias: {
'../../theme.config$': path.join(appPaths.client, 'semantic-ui/theme.config'),
'@client': appPaths.client,
'@suir': 'semantic-ui-react/dist/commonjs',
},
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx',
],
modules: [
appPaths.src,
'node_modules',
],
},
};
const webpackConfig = wpMerge(
baseWebpackConfig,
envWebpackConfig,
);
module.exports = webpackConfig;