-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.ts
128 lines (124 loc) · 4.05 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
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
/// <reference types="./build-shims" />
import webpack, { Configuration } from "webpack";
import fs from "fs";
import HtmlWebpackPlugin from "html-webpack-plugin";
import HtmlWebpackInlineSourcePlugin from "html-webpack-inline-source-plugin";
import CopyPlugin from "copy-webpack-plugin";
import { compile, CompilerOptions } from "vue-template-compiler";
import svgToMiniDataURI from "mini-svg-data-uri";
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
import "webpack-dev-server";
import { fileURLToPath } from 'url';
/* const expose = {
jquery: "jQuery",
"beatbox.js": "Beatbox"
}; */
export default async (env: any, argv: any): Promise<Configuration> => {
const isDev = argv.mode == "development";
return {
entry: fileURLToPath(new URL('./src/app.ts', import.meta.url)),
output: {
path: fileURLToPath(new URL("./dist/", import.meta.url)),
filename: "ror-player.js",
publicPath: "/" // Workaround for https://github.com/DustinJackson/html-webpack-inline-source-plugin/issues/57
},
resolve: {
extensions: [ ".ts", ".js" ],
extensionAlias: {
".js": [".js", ".ts"],
".cjs": [".cjs", ".cts"],
".mjs": [".mjs", ".mts"]
},
alias: {
vue: "vue/dist/vue.runtime.esm.js"
}
},
module: {
rules: [
{ test: /\.css$/, use: [ "style-loader", "css-loader" ] },
{ test: /\.scss$/, use: [ "style-loader", "css-loader", "sass-loader" ]},
{ test: /\.ts$/, loader: "ts-loader" },
{ test: /\.(png|jpe?g|gif)$/, type: "asset/inline" },
{
test: /\.(svg)$/,
type: 'asset/inline',
generator: {
dataUrl: (content: any) => {
content = content.toString();
return svgToMiniDataURI(content);
}
}
},
{
test: /\.html$/,
loader: "html-loader",
options: {
sources: {
list: [
{ tag: "img", attribute: "src", type: "src" },
{ tag: "link", attribute: "href", type: "src", filter: (tag: any, attr: any, attrs: any) => attrs.some((a: any) => a.name == "rel" && ["icon"].includes(a.value)) },
]
}
}
},
{
test: /\.vue$/,
loader: "vue-template-loader",
options: {
transformAssetUrls: {
img: 'src'
},
compiler: {
compile: (template: string, options: CompilerOptions) => compile(template, { ...options, whitespace: "condense" })
}
}
},
{ test: /\.md$/, use: [ "html-loader", "markdown-loader" ]},
// Currently breaks ESM imports
/* ...await Promise.all(Object.entries(expose).map(async ([key, value]) => ({
test: fileURLToPath(await import.meta.resolve!(key)),
loader: "expose-loader",
sideEffects: false,
options: {
exposes: [value]
}
}))) */
],
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
}),
new HtmlWebpackPlugin({
template: "./index.html",
inlineSource: "\.js$",
inject: "body"
}),
...(isDev ? [] : [new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin)]),
new CopyPlugin({
patterns: [
{ from: fileURLToPath(new URL('./src/sw.js', import.meta.url)), to: fileURLToPath(new URL('./dist/sw.js', import.meta.url)) },
{ from: fileURLToPath(new URL('./assets/img/app-512.png', import.meta.url)), to: fileURLToPath(new URL('./dist/app-512.png', import.meta.url)) },
{ from: fileURLToPath(new URL('./assets/img/app-180.png', import.meta.url)), to: fileURLToPath(new URL('./dist/app-180.png', import.meta.url)) },
{ from: fileURLToPath(new URL('./assets/img/favicon.svg', import.meta.url)), to: fileURLToPath(new URL('./dist/favicon.svg', import.meta.url)) },
{ from: fileURLToPath(new URL('./assets/manifest.json', import.meta.url)), to: fileURLToPath(new URL('./dist/manifest.json', import.meta.url)) }
]
}),
new webpack.EnvironmentPlugin({
DISABLE_SW: isDev
}),
//new BundleAnalyzerPlugin()
],
mode: isDev ? "development" : "production",
devtool: isDev ? "eval-cheap-module-source-map" : "source-map",
performance: {
hints: false
},
devServer: {
hot: "only",
allowedHosts: "all"
}
}
};