-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
74 lines (60 loc) · 1.93 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
'use strict';
const ExternalModule = require('webpack/lib/ExternalModule')
const webpack = require('webpack')
const nativeExternalModuleGetSourceForCommonJsExternal = ExternalModule.prototype.getSourceForCommonJsExternal
const externalNodeModules = ['url', 'http', 'https', 'stream', 'form-data', 'buffer']
ExternalModule.prototype.getSourceForCommonJsExternal = function(moduleAndSpecifiers) {
if (typeof moduleAndSpecifiers === 'string' && externalNodeModules.includes(moduleAndSpecifiers)) {
//we must not include external NodeJs packages to "dist" build by several reasons,
//one of these is problem with ReactNative http://support.backendless.com/topic/latest-npm-version-4-1-6-not-working-with-react-native
return [
'throw new Error(\'',
'This Backendless JS SDK assembly is not intended for Node.js environment. ' +
'You should use "lib" folder modules instead. ' +
'For any questions please contact as at http://support.backendless.com/',
'\')'
].join('');
}
return nativeExternalModuleGetSourceForCommonJsExternal.apply(this, arguments)
}
const isProd = process.env.NODE_ENV === 'production'
const uglify = new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
unsafe : true,
unsafe_comps: true,
warnings : false,
screw_ie8 : false
},
mangle : {
screw_ie8: false
},
output : {
screw_ie8: false
},
sourceMap : true
})
module.exports = {
devtool: 'source-map',
target: 'web',
externals: function(context, moduleName, callback) {
if (externalNodeModules.includes(moduleName)) {
return callback(null, `commonjs ${moduleName}`);
}
callback();
},
module: {
rules: [
{
test : /\.js$/,
exclude: /node_modules/,
loader : 'babel-loader'
}
]
},
output: {
library : 'BackendlessRequest',
libraryTarget: 'umd'
},
plugins: isProd ? [uglify] : []
}