-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
127 lines (107 loc) · 4.73 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
const webpack = require("@nativescript/webpack");
const CircularDependencyPlugin = require('circular-dependency-plugin');
const { IgnorePlugin } = require('webpack');
const path = require('path');
const configuredCircularPlugin = new CircularDependencyPlugin(
{
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules|node_modules\/@nativescript\/.*/,
// include specific files based on a RegExp
include: /dir/,
// add errors to webpack instead of warnings
failOnError: false,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: true,
// set the current working directory for displaying module paths
cwd: process.cwd(),
});
module.exports = (env) => {
webpack.init(env);
//config.resolve.alias.set('tns-core-modules', '@nativescript/core');
// Learn how to customize:
// https://docs.nativescript.org/webpack
// added for sake of libp2p dependencies
// using a function
webpack.mergeWebpack(env => {
// return the object to be merged
return {
resolve: {
mainFields: ['module', 'main', 'browser'],
alias: { "tns-core-modules/utils/utils": "@nativescript/core/utils",
"tns-core-modules": "@nativescript/core", //somehow still necessary for old node modules
"application": "@nativescript/core/application",
//"url": "whatwg-url", //better replacement
//"randombytes" : "nativescript-randombytes", // for crypto library
//"nativescript-nodeify" : "/customized-node-modules/nativescript-nodeify",
//"nativescript-urlhandler" : "/customized-node-modules/nativescript-urlhandler",
//"ipfs-utils" : "/customized-node-modules/ipfs-utils",
//"crypto" : '/customized-node-modules/nativescript-crypto',
"nativescript-wear-os" : '/customized-node-modules/nativescript-wear-os'
},
fallback: {
// assert: require.resolve('assert'),
// buffer: require.resolve('buffer'),
//console: require.resolve('console-browserify'),
//constants: require.resolve('constants-browserify'),
// domain: require.resolve('domain-browser'),
events: require.resolve('events'),
//http: require.resolve('stream-http'),
//https: require.resolve('https-browserify'),
//os: require.resolve('os-browserify/browser'),
//path: require.resolve('path-browserify'),
// punycode: require.resolve('punycode'),
// process: require.resolve('process/browser'),
// querystring: require.resolve('querystring-es3'),
//stream: require.resolve('stream-browserify'),
// string_decoder: require.resolve('string_decoder'),
// sys: require.resolve('util'),
//timers: require.resolve('timers-browserify'),
//tty: require.resolve('tty-browserify'),
//url: require.resolve('whatwg-url'), conflict with ui-webview
util: require.resolve('util'),
//vm: require.resolve('vm-browserify'),
//zlib: require.resolve('browserify-zlib'),
"fs": false,
"child_process": false,
"net": false,
"tls": false,
"dns": false,
"dgram": false,
"_stream_transform": require.resolve("readable-stream"),
},
}
}
})
// using the IgnorePlugin so we don't get errors from direc
webpack.chainWebpack(config => {
// we add the plugin
config.plugin('IgnorePlugin').use(IgnorePlugin, [{ resourceRegExp: /backup/ }])
//config.plugin('CircularDependencyPlugin').use(CircularDependencyPlugin, [configuredCircularPlugin])
});
webpack.Utils.addCopyRule({
from: '**/*.*',
to: 'assets/www',
// the context of the "from" rule:
context: webpack.Utils.project.getProjectFilePath('www')
});
// That's it, config will be resolved now
const config = webpack.resolveConfig()
// After this we put changes to resolved config
config.module.rules.push(
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: [
// warps elm code
{ loader: path.resolve('./elm-code-wrap-loader') },
{ loader: 'elm-webpack-loader' ,
options: {
verbose: true,
debug: true
}},
]
}
)
return config;
};