-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
94 lines (90 loc) · 2.88 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
import { resolve } from 'path'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import svgToMiniDataURI from 'mini-svg-data-uri'
import { type Configuration } from 'webpack'
import 'webpack-dev-server' // Augment "Configuration" type
import { author, description, homepage, keywords, name, repository, title } from './package.json'
import { PDFPrinter } from './tooling/pdf-printer-plugin'
const src = resolve(__dirname, 'src')
const dist = resolve(__dirname, 'dist')
const tools = resolve(__dirname, 'tooling')
const out = 'ccjmne-resume'
export default (
_env: string,
{ mode = 'production', port = '8042' }: { mode?: 'production' | 'development', port?: string } = {},
): Configuration => ({
entry: {
scss: resolve(src, 'index.scss'),
main: resolve(src, 'index.ts'),
},
module: {
rules: [{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
}, {
test: /exported-vars\.scss$/,
use: [
'style-loader',
'css-modules-typescript-loader',
{ loader: 'css-loader', options: { modules: 'icss' } },
'sass-loader',
],
}, {
test: /(?<!exported-vars)\.scss?$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
exclude: /node_modules/,
}, {
test: /\.(png|jpe?g|gif)$/i,
resourceQuery: /dataURI/,
use: { loader: 'url-loader', options: { limit: true } },
}, {
test: /\.svg$/,
enforce: 'pre',
use: 'svgo-loader',
}, {
test: /\.svg$/, // w/o `?template` query param
resourceQuery: /template/,
use: resolve(tools, 'template-element-loader.ts'),
}, {
test: /\.svg$/, // w/ `?template` query param
resourceQuery: query => !/template/.test(query),
// see https://webpack.js.org/guides/asset-modules/
type: 'asset/inline',
generator: {
dataUrl: (content: string | Buffer) => svgToMiniDataURI(String(content)),
},
}],
},
resolve: {
alias: { src },
extensions: ['.tsx', '.ts', '.js'],
modules: ['src', 'node_modules'],
},
devtool: mode === 'development' ? 'eval' : false,
devServer: {
port,
devMiddleware: {
index: `${out}.html`,
},
},
output: {
path: dist,
},
plugins: [
...mode === 'production' ? [new CleanWebpackPlugin()] : [],
new HtmlWebpackPlugin({
title: name,
meta: { author, description, repository, keywords: keywords.join(', ') },
template: resolve(src, 'index.html'),
filename: resolve(dist, `${out}.html`),
}),
new PDFPrinter({
...mode === 'production' ? { scheme: 'file', path: resolve(dist, `${out}.html`) } : { port },
output: resolve(dist, `${out}.pdf`),
properties: { title, author, subject: description, keywords: keywords.join(', '), creator: `${name} (${homepage})` },
blocking: mode === 'production',
}),
],
})