-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
104 lines (100 loc) · 3.22 KB
/
webpack.config.js
File metadata and controls
104 lines (100 loc) · 3.22 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
import fs from 'fs';
import path from 'path';
import { URL } from 'url';
import CopyWebpackPlugin from 'copy-webpack-plugin';
// ESM-compatible __dirname (fix for Windows)
const __dirname = path.dirname(
new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')
);
// Reusable function to generate patterns for all items in a folder
function copyFolder(srcDir, destDir) {
const absSrcDir = path.resolve(__dirname, srcDir);
if (!fs.existsSync(absSrcDir)) return [];
return fs.readdirSync(absSrcDir).map(item => ({
from: path.join(absSrcDir, item),
to: path.join(destDir, item)
}));
}
export default {
mode: 'development', // Change to 'production' for minified output
target: 'webworker',
entry: {
sidepanel: path.resolve(__dirname, 'src/sidepanel.ts'),
background: path.resolve(__dirname, 'src/background.ts'),
// modelWorker: path.resolve(__dirname, 'src/modelworker.ts'), // Removed as part of migration to background-based architecture
scriptingReadabilityHelper: path.resolve(__dirname, 'src/scriptingReadabilityHelper.ts'),
pageExtractor: path.resolve(__dirname, 'src/PageExtractor.ts'),
db: path.resolve(__dirname, 'src/DB/db.ts'),
content: path.resolve(__dirname, 'src/content.ts'),
indexedDBBackendWorker: path.resolve(__dirname, 'src/DB/indexedDBBackendWorker.ts'),
},
output: {
path: path.resolve(__dirname, 'TabAgentDist/Extension'),
filename: (pathData) => {
if (pathData.chunk && pathData.chunk.name === 'indexedDBBackendWorker') {
return 'DB/[name].js'; // Output worker to dist/DB/indexedDBBackendWorker.js
}
return '[name].js'; // All others to dist/[name].js
},
chunkFilename: 'assets/[name]-[contenthash].js',
assetModuleFilename: 'assets/[name]-[contenthash][ext]',
clean: true,
},
devtool: 'source-map',
optimization: {
minimize: false,
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'manifest.json', to: '.' },
{ from: 'src/sidepanel.html', to: '.' },
{ from: 'src/output.css', to: '.' },
{ from: 'src/sidepanel.css', to: '.' },
{ from: 'src/events', to: 'events' },
{ from: 'src/theme-loader.js', to: '.' },
...copyFolder('src/model', 'model'),
...copyFolder('src/assets', 'assets'),
],
}),
],
resolve: {
extensions: ['.ts', '.js', '.json'],
alias: {
'@vendor': path.resolve(__dirname, 'src/vendor'),
'@huggingface/transformers': path.resolve(
__dirname,
'node_modules/@huggingface/transformers/dist/transformers.web.min.js'
),
},
fallback: {
fs: false,
path: false,
crypto: false,
module: false
}
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
include: [path.resolve(__dirname, 'src/assets/icons')],
type: 'asset/resource',
generator: {
filename: 'icons/[name][ext]'
}
},
// Add loaders here if you need to handle CSS, images, etc.
],
},
ignoreWarnings: [
{
message: /Critical dependency: Accessing import\.meta directly is unsupported/,
},
],
};