-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.dev.ts
More file actions
110 lines (103 loc) · 2.51 KB
/
webpack.config.dev.ts
File metadata and controls
110 lines (103 loc) · 2.51 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
import CopyPlugin from 'copy-webpack-plugin';
import glob from 'glob';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import type { Configuration } from 'webpack';
const projectPath = __dirname;
const distPath = `${projectPath}/dist`;
const srcPath = `${projectPath}/src`;
const viewsPath = `${projectPath}/views`;
const scriptsPath = `${srcPath}/scripts`;
const pagesPath = `${srcPath}/pages`;
const entries = glob.sync(`${scriptsPath}/**/*.ts`)
.filter(name => !/\.d\.ts$/.test(name))
.map(name => name.slice(scriptsPath.length + 1, -3));
const pages = glob.sync(`${pagesPath}/**/*.ejs`)
.map(name => name.slice(pagesPath.length + 1, -4));
const htmls = pages.map(name => (
new HtmlWebpackPlugin({
chunks: [name],
publicPath: '/',
base: '',
template: `${pagesPath}/${name}.ejs`,
filename: `${viewsPath}/${name}.ejs`,
})
));
console.log('\x1B[33mbuilding...\x1B[0m');
const config: Configuration = {
mode: 'development',
watch: true,
devtool: 'inline-source-map',
entry: Object.fromEntries(entries.map(name => (
[name, [`${scriptsPath}/${name}.ts`]]
))),
output: {
filename: 'javascripts/[name].js',
path: distPath,
},
optimization: {
splitChunks: {
chunks: 'all',
maxSize: 25000,
},
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
{
test: /\.ejs$/,
loader: 'html-loader',
},
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
},
{
test: /\.(svg|eot|woff|woff2|ttf|jpg|png|gif)$/,
type: 'asset/resource',
generator: {
filename: 'assets/[hash][ext][query]',
},
},
],
},
plugins: [
...htmls,
new MiniCssExtractPlugin({
filename: 'stylesheets/[name].css',
}),
new CopyPlugin({
patterns: [
{ from: 'public' },
],
}),
],
resolve: {
roots: [srcPath],
modules: [
'node_modules',
srcPath,
],
extensions: ['.ts', '.js'],
plugins: [
new TsconfigPathsPlugin(),
],
},
stats: {
preset: 'minimal',
assets: false,
modules: false,
},
};
export default config;