This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
149 lines (140 loc) · 4.95 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
138
139
140
141
142
143
144
145
146
147
148
149
const path = require('path');
const webpack = require('webpack');
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
require('dotenv').config();
process.env.APP_ENV === 'dev' ? process.env.NODE_ENV = 'development' : process.env.NODE_ENV = 'production';
console.log('Webpack run as ' + process.env.NODE_ENV);
const plugins = [
new MiniCssExtractPlugin({
filename: 'css/[name]' + (process.env.NODE_ENV !== 'development' ? '.[hash]' : '') + '.css',
}),
new HtmlWebpackPlugin({
template: '!!raw-loader!./src/index.ejs',
filename: path.resolve(__dirname, 'views/index.ejs'),
inject: 'body'
}),
// Ignore Moment Locales
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new WebpackPwaManifest({
name: 'CBatmo',
short_name: 'CBatmo',
description: 'A Netatmo Weather Station Web-APP for Raspberry Pi and official Raspberry touchscreen',
background_color: '#1E1E1E',
crossorigin: null,
display: 'standalone',
orientation: 'landscape'
}),
// Fix for blueprintjs Uncaught ReferenceError: process is not defined
new webpack.DefinePlugin({
"process.env": "{}",
global: {}
})
];
if (process.env.NODE_ENV === 'development') {
plugins.push(new WebpackShellPluginNext({
onBuildEnd: {
scripts: ['node server.js'],
blocking: false,
parallel: true
}
}));
}
if (process.env.NODE_ENV === 'analyse') {
plugins.push(new BundleAnalyzerPlugin())
}
module.exports = {
mode: process.env.NODE_ENV,
entry: {
'bundle': './src/index.tsx',
},
resolve: {
extensions: ['.js', '.ts', '.tsx']
},
module: {
rules: [
{
test: /\.(otf|eot|ttf|woff2?)$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
outputPath: 'fonts/',
publicPath: '/fonts'
}
}
},
{
test: /\.(css|sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader', // translates CSS into CommonJS
options: {
sourceMap: process.env.NODE_ENV === 'development'
},
},
{
loader: 'sass-loader', // compiles Sass to CSS
options: {
sourceMap: process.env.NODE_ENV === 'development'
},
},
]
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: 'file-loader',
options: {
limit: 10000,
outputPath: 'img/',
publicPath: '/img'
}
},
{
loader: 'image-webpack-loader',
options: {
optipng: {
progressive: true,
optimizationLevel: 7,
interlaced: false,
},
mozjpeg: {
quality: 65
},
pngquant: {
quality: [0.65, 0.90],
speed: 4
},
svgo: {
plugins: [
{
removeViewBox: false
},
{
removeEmptyAttrs: false
}
]
}
}
}
]
},
{ test: /\.(t|j)sx?$/, use: { loader: 'awesome-typescript-loader' }, exclude: /node_modules/ },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{ test: /\.html$/, loader: 'html-loader' }
]
},
plugins,
devtool: process.env.NODE_ENV === 'development' && 'source-map',
output: {
publicPath: '/',
path: path.resolve(__dirname, 'public'),
filename: '[name]' + (process.env.NODE_ENV !== "development" ? '.[hash]' : '') + '.js'
}
};