-
Notifications
You must be signed in to change notification settings - Fork 149
/
webpack.config.js
104 lines (100 loc) · 2.58 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
import glob from 'glob'
import path from 'path'
import webpack from 'webpack'
import { createRequire } from 'node:module'
import { readFileSync } from 'fs'
// import pkg from './package.json' assert { type: 'json' }
const pkg = JSON.parse(readFileSync('./package.json'))
const require = createRequire(import.meta.url)
const config = {
plugins: [
// deal with the funky invokation of p-queue using "await import"
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
// Webpack 5 no longer polyfills 'process'
new webpack.ProvidePlugin({
process: 'process/browser.js'
}),
// as per https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
],
target: ['web'],
resolve: {
fallback: {
// BREAKING CHANGE: webpack < 5 used to include polyfills for
// node.js core modules by default. This is no longer the
// case.
assert: false,
buffer: require.resolve('buffer/'),
fs: false,
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify'),
util: false,
os: require.resolve('os-browserify')
}
}
}
// module.exports = [
export default [
{
...config,
mode: 'production',
entry: './src/entrypoints/browserlevel.js',
output: {
path: path.resolve('dist'),
filename: 'search-index-' + pkg.version + '.js',
library: 'SearchIndex'
}
},
{
...config,
mode: 'production',
entry: './src/entrypoints/browserlevel.js',
experiments: {
outputModule: true
},
output: {
publicPath: '/lib/',
path: path.resolve('dist'),
filename: 'search-index-esm-' + pkg.version + '.js',
library: {
type: 'module'
}
}
},
{
...config,
plugins: [
...config.plugins,
new webpack.DefinePlugin({
process: {
env: {
SI_TEST_ENTRYPOINT: '"entrypoints/browserlevel.js"'
}
}
})
],
// Use "mode: 'production" to keep bundle size low(ish- around 3mb)
// possibly it would be good to have some kind of code splitting
// instead
mode: 'production',
entry: glob.sync('./test/src/*-test.js', {
// entry: glob.sync('./test/src/init-test.js', {
ignore: './test/src/swap-level-test.js' // ignore the node-only level test
}),
output: {
path: path.resolve('test/sandbox'),
filename: 'browser-tests.js'
},
devServer: {
static: {
directory: './demo2'
},
compress: true,
port: 3030
}
}
]