-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
146 lines (142 loc) · 3.33 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* @license
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
*/
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const webpackBabelConfig = {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'entry',
corejs: '3.0.0',
targets: {
browsers: '> 0.25%, not dead'
}
}
]
],
plugins: ['@babel/plugin-transform-runtime']
}
}
}
]
};
module.exports = [
{ // ES6
mode: 'production',
entry: {
pryv: {
import: componentPath('pryv', 'src/browser-index.js'),
library: {
name: 'pryv',
type: 'var'
}
},
'pryv-monitor': componentPath('pryv-monitor', 'src/browser-index.js'),
'pryv-socket.io': componentPath('pryv-socket.io', 'src/browser-index.js')
},
output: {
filename: '[name]-es6.js',
path: distPath()
},
devtool: 'source-map'
},
{ // ES5
mode: 'production',
entry: {
pryv: {
import: componentPath('pryv', 'src/browser-index.js'),
library: {
name: 'pryv',
type: 'var'
}
},
'pryv-monitor': ['core-js/stable', componentPath('pryv-monitor', 'src/browser-index.js')],
'pryv-socket.io': componentPath('pryv-socket.io', 'src/browser-index.js')
},
output: {
filename: '[name].js',
path: distPath()
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'examples', to: 'examples' }
]
})
],
devtool: 'source-map',
module: webpackBabelConfig
},
{ // ES5 all-in-one bundle (with socket.io and monitor)
mode: 'production',
entry: {
'pryv-socket.io-monitor': {
import: componentPath('pryv', 'src/browser-index-bundle.js'),
library: {
name: 'pryv',
type: 'var'
}
}
},
output: {
filename: '[name].js',
path: distPath()
},
devtool: 'source-map',
module: webpackBabelConfig,
resolve: {
fallback: {
fs: false,
path: false
}
}
},
{ // browser test suite (ES6)
mode: 'development',
entry: {
'browser-tests': './test/browser-tests.js'
},
output: {
filename: 'tests.js',
path: path.join(__dirname, 'test-browser/')
},
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /zombie/ }),
new CopyPlugin({
patterns: [
{ from: componentPath('pryv', 'test/browser-index.html'), to: 'index.html' },
{ from: distPath('pryv.js') },
{ from: distPath('pryv.js.map') }
]
}),
new webpack.ProvidePlugin({
process: 'process/browser'
})
],
devtool: 'source-map',
resolve: {
fallback: {
fs: false,
path: false
}
}
}
];
function componentPath (component, ...subPath) {
return './' + path.join('./components', component, ...subPath);
}
function distPath (...subPath) {
return path.join(__dirname, 'dist', ...subPath);
}