-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
100 lines (96 loc) · 2.85 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
95
96
97
98
99
100
import { resolve } from 'path';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import HtmlWebpackPlugin, { MinifyOptions } from 'html-webpack-plugin';
import { Configuration, EntryObject, WebpackPluginInstance } from 'webpack';
import { author, description, keywords, name } from './package.json';
const HTML_MINIFY_OPTS: MinifyOptions = {
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true,
removeAttributeQuotes: true,
useShortDoctype: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
removeScriptTypeAttributes: true,
};
const src = resolve(__dirname, 'src');
const demo = resolve(__dirname, '.');
const dist = resolve(__dirname, 'dist');
export default (
_env: string,
{ mode }: { mode?: 'production' | 'development' } = { mode: 'production' },
): Configuration => ({
entry: {
main: {
import: resolve(src, 'orca-logo/orca-logo.ts'),
filename: 'orca-logo.min.js',
},
},
output: {
path: dist,
},
module: {
rules: [{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ['ts-loader'],
}, {
test: /\.scss$/,
exclude: /node_modules/,
use: [
{ loader: 'css-loader', options: { exportType: 'css-style-sheet' } },
'sass-loader',
],
}, {
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
esModule: false,
sources: {
list: [
{ tag: 'img', attribute: 'src', type: 'src' },
{ tag: 'img', attribute: 'data-src', type: 'src' },
{ tag: 'video', attribute: 'src', type: 'src' },
{ tag: 'video', attribute: 'data-src', type: 'src' },
],
},
minimize: mode === 'production' && HTML_MINIFY_OPTS,
},
},
],
}],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', 'vert', 'frag', '...'],
// IMPORTANT: prioritise 'global' node modules, for extending modules (e.g.: d3-selection-multi enhances d3-selection)
modules: [src, resolve(__dirname, 'node_modules'), 'node_modules'],
mainFields: ['webpack', 'module', 'browser', 'web', 'browserify', ['jam', 'main'], 'main'],
},
plugins: ([] as WebpackPluginInstance[]).concat(
mode === 'production' ? new CleanWebpackPlugin() : [],
new HtmlWebpackPlugin({
title: name,
meta: {
author,
description,
keywords: keywords.join(', '),
charset: 'UTF-8',
},
template: resolve(demo, 'index.html'),
filename: resolve(dist, 'index.html'),
minify: HTML_MINIFY_OPTS,
}),
),
devtool: mode === 'development' ? 'source-map' : false,
devServer: {
hot: true,
},
optimization: {
runtimeChunk: mode === 'development' && {
name: (entrypoint: EntryObject) => `runtime~${entrypoint.name}`,
},
},
});