-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathwebpack.config.js
71 lines (66 loc) · 1.71 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
// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
// Node module: @loopback/example-webpack
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
const path = require('path');
const webpack = require('webpack');
/**
* Common configuration for both Node.js and Web
*/
const baseConfig = {
mode: 'production',
entry: './dist/index.js',
// Uncomment the following line to enable source map
// devtool: 'source-map',
resolve: {
extensions: ['.js'],
fallback: {
// Polyfill for Node.js core modules
events: require.resolve('events/'),
process: require.resolve('process/browser'),
assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
util: require.resolve('util/'),
},
},
};
/**
* Configuration for a Node.js compatible bundle
*/
const nodeConfig = {
...baseConfig,
name: 'node',
target: 'node', // For Node.js
output: {
filename: 'bundle-node.js',
path: path.resolve(__dirname, 'dist'),
library: {
type: 'umd', // We can use `commonjs2` for Node.js
},
},
};
/**
* Configuration for a browser compatible bundle
*/
const webConfig = {
...baseConfig,
name: 'web',
target: 'web', // For browsers
output: {
filename: 'bundle-web.js',
path: path.resolve(__dirname, 'dist'),
library: {
name: 'LoopBack',
type: 'umd',
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({process: ['process']}),
],
};
// Expose two configurations for `webpack`. Use `--config-name <node|web>` to
// select a named entry.
module.exports = [nodeConfig, webConfig];