-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.worker.config.js
82 lines (80 loc) · 2.25 KB
/
webpack.worker.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
// @ts-nocheck
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable import/no-commonjs */
const WrapperPlugin = require('wrapper-webpack-plugin');
/**
* I'm making a UMD module myself for the following reasons:
* 1. Before checking availabilities of module, define(), and ES6, it should
* initiate itself if it is run in the web worker environment.
* 2. If none of above environments available it should be attacted to
* 'sqliteWasm' object, which is already defined using <script> tag, as a
* plugin.
*/
/* global WorkerGlobalScope, define */
/* eslint-disable prettier/prettier, vars-on-top, no-var, dot-notation, no-param-reassign, no-console */
function workerUMD(root, factory) {
if (typeof WorkerGlobalScope !== 'undefined' &&
self instanceof WorkerGlobalScope) {
var initWorker = factory();
initWorker();
}
else if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports['worker'] = factory();
else {
root['worker'] = factory();
if (typeof sqliteWasm === 'undefined' || typeof sqliteWasm !== 'function')
console.warn('sqliteWasm.worker may not be loaded correctly.');
}
}
/* eslint-enable prettier/prettier, vars-on-top, no-var, dot-notation, no-param-reassign, no-console */
module.exports = {
plugins: [
new WrapperPlugin({
afterOptimizations: true,
test: /\.js$/,
header: `
(
${workerUMD.toString()}
)(
typeof sqliteWasm !== 'undefined'
? sqliteWasm
: typeof self !== 'undefined'
? self
: this,
function() {
return function() {`,
// Worker Code (lib/worker.js) is placed here.
footer: `
}
},
);`,
}),
],
entry: {
worker: './lib/worker.js',
},
mode: 'development',
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|jsx|mjs)$/,
type: 'javascript/auto',
exclude: [/node_modules/, /build/],
use: 'eslint-loader',
},
{
test: /\.m?js$/,
type: 'javascript/auto',
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
],
},
};