-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (102 loc) · 2.45 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
import * as path from 'path';
import * as fs from 'fs';
import { fileURLToPath } from 'url';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import WarningsToErrorsPlugin from 'warnings-to-errors-webpack-plugin';
import webpack from 'webpack';
const isProduction = process.env.NODE_ENV === 'production';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootPath = path.resolve(__dirname);
const srcPath = path.resolve(rootPath, 'src');
const outPath = path.resolve(rootPath, 'dist');
const Mode = isProduction ? 'production' : 'development';
const productionPlugins = [
new WarningsToErrorsPlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
];
const developmentPlugins = [
//
];
/** @type {Partial<import('webpack').Configuration>} */
let Config = {
entry: {
index: './src/index.ts'
},
mode: Mode,
output: {
path: outPath,
filename: '[name].js',
clean: true,
strictModuleErrorHandling: true,
strictModuleExceptionHandling: true
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(srcPath, 'index.html')
}),
new MiniCssExtractPlugin({
filename: 'index.css'
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(srcPath, 'favicons'),
to: path.resolve(outPath, 'favicons')
}
]
})
],
module: {
rules: [
{
test: /\.(tsx|ts)$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.m?js$/,
resolve: {
fullySpecified: false
}
},
{
test: /\.css$/i,
include: srcPath,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
'@nxtlvlsoftware/alpine-typescript': path.resolve(
rootPath,
JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))).dependencies['@nxtlvlsoftware/alpine-typescript'].substring(5)
)
}
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
devServer: {
static: outPath,
hot: true,
compress: true,
historyApiFallback: true
}
};
if (isProduction) {
Config.devtool = 'hidden-source-map';
Config.plugins.push(...productionPlugins);
} else {
Config.devtool = 'inline-source-map';
Config.plugins.push(...developmentPlugins);
}
export default Config;