-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
75 lines (66 loc) · 1.64 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
const path = require('path');
const fs = require('fs');
const AfterBuildPlugin = require('@fiverr/afterbuild-webpack-plugin');
/**
* ./dist/feeder-node.js contains a reference to `self`; replace this reference to `self`
* with `this` so that the library doesn't break in server-side-rendered applications
*/
function replaceSelfWithThis() {
let filePath = path.resolve(__dirname, 'dist', 'feeder-node.js')
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) return console.error(err);
let newFileString = data.replace(/self/g, 'this');
fs.writeFile(filePath, newFileString, 'utf8', (err) => { console.error(err) });
});
}
let commonConfig = {
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: 'defaults' }]
]
}
}
},
],
},
mode: 'production',
plugins: [
new AfterBuildPlugin(replaceSelfWithThis)
]
}
let workletConfig = Object.assign({}, commonConfig, {
entry: './src/feeder-node.worklet.js',
output: {
filename: 'feeder-node.worklet.js',
path: path.resolve(__dirname, 'dist')
},
});
let workerConfig = Object.assign({}, commonConfig, {
entry: './src/feeder-node.worker.js',
output: {
filename: 'feeder-node.worker.js',
path: path.resolve(__dirname, 'dist')
},
});
let moduleConfig = Object.assign({}, commonConfig, {
entry: './src/index.js',
output: {
filename: 'feeder-node.js',
path: path.resolve(__dirname, 'dist'),
library: 'FeederNode',
libraryTarget: 'umd',
globalObject: 'this'
},
});
module.exports = [
moduleConfig,
workletConfig,
workerConfig
];