-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (107 loc) · 3.04 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
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const svelte = require('./svelte.config');
require('dotenv').config();
/** @type {import('webpack').Configuration} */
module.exports = (_ /* env */, argv) => ({
mode: argv.mode,
entry: './src/index.js',
output: {
filename: argv.mode === 'production' ? '[name]-[chunkhash].js' : '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: argv.mode === 'production' ? '/hfy-epub/' : '/',
},
devtool: argv.mode === 'production' ? false : 'source-map',
resolve: {
alias: {
svelte: path.resolve('node_modules', 'svelte/src/runtime'),
},
extensions: ['.mjs', '.js', '.svelte', '.ts'],
mainFields: ['svelte', 'browser', 'module', 'main'],
conditionNames: ['svelte', 'browser'],
fallback: {
fs: false,
path: require.resolve("path-browserify"),
}
},
module: {
rules: [
{
test: /\.(html|svelte|svg)$/,
use: {
loader: 'svelte-loader',
options: {
...svelte,
emitCss: argv.mode === 'production',
hotReload: argv.mode !== 'production',
compilerOptions: {
dev: argv.mode !== 'production',
},
hotOptions: {
preserveLocalState: true,
}
}
},
},
{
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: {
fullySpecified: false,
},
},
argv.mode === 'production' && {
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false, // necessary if you use url('/path/to/some/asset.png|jpg|gif')
sourceMap: argv.mode !== 'production',
}
}
]
},
{
test: /\.tsx?$/,
loader: "ts-loader",
},
{
test: /public/,
type: 'asset/resource',
generator: {
filename: '[name][ext]',
}
},
].filter(Boolean),
},
devServer: {
static: false,
historyApiFallback: true,
client: {
progress: true,
},
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "public", filter: (pth) => !pth.endsWith('favicon_orig.png') },
{ from: "node_modules/tinymce", filter: (pth) => pth.endsWith('.min.js') || pth.endsWith('.min.css'), to: "tinymce" },
],
}),
new HtmlWebpackPlugin({
title: 'r/HFY epub',
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(require("./package.json").version),
DEV: JSON.stringify(argv.mode !== 'production'),
TINY_API_KEY: JSON.stringify(process.env.TINY_API_KEY),
}),
argv.mode === 'production' && new MiniCssExtractPlugin({
filename: argv.mode === 'production' ? '[name]-[chunkhash].css' : '[name].css',
}),
].filter(Boolean),
});