-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
81 lines (70 loc) · 2.2 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
const path = require('path');
class MyPlugin {
apply(compiler) {
compiler.hooks.emit.tap('MyPlugin', (compilation) => {
// Target the specific output file
const fileName = 'index.js'; // Match output.filename
// Ensure the file exists in assets
if (!compilation.assets[fileName]) {
console.error('Output file not found in compilation assets');
return;
}
// Get the bundled file content
const fileContent = compilation.assets[fileName].source();
// Custom UMD header with axios passed to factory
const header = `
if (! axios && typeof(require) === 'function') {
var axios = require('axios');
}
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.openetl = factory();
}(this, (function () {`;
const footer = ` return openetl;
})));`;
// Combine header, original content, and footer
const updatedFileContent = header + '\n\n' + fileContent + '\n\n' + footer;
// Replace the bundled file content
compilation.assets[fileName] = {
source: () => updatedFileContent,
size: () => updatedFileContent.length,
};
});
}
}
let dependencies = {
axios: "axios"
}
const webpack = {
target: [ 'node' ],
entry: './src/index.ts',
mode: 'production',
resolve: {
extensions: ['.ts', '.js'], // Resolve .ts and .js files
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
library: 'openetl',
globalObject: 'default'
},
module: {
rules: [
{
test: /\.ts$/, // Match .ts files
use: 'ts-loader', // Use ts-loader to compile TypeScript
exclude: /node_modules/,
},
],
},
externals: dependencies,
plugins: [new MyPlugin()],
stats: {
warnings: false
},
optimization: {
minimize: false,
},
};
module.exports = webpack;