forked from nativescript-community/plugin-seed-demo-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
72 lines (64 loc) · 2.38 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
const webpack = require('@nativescript/webpack');
const fs = require('fs');
const { resolve } = require('path');
let snippetConfig;
if (fs.existsSync('../demo-snippets/webpack.config.ng.js')) {
snippetConfig = require('../demo-snippets/webpack.config.ng.js');
}
module.exports = (env) => {
if (fs.existsSync('../demo-snippets/ng')) {
webpack.Utils.addCopyRule({
from: '../demo-snippets/ng',
to: webpack.Utils.project.getProjectRootPath() + '/src/app/plugin'
});
}
if (fs.existsSync('../demo-snippets/assets')) {
webpack.Utils.addCopyRule({
from: '../demo-snippets/assets',
to: '.'
});
}
if (fs.existsSync('../demo-snippets/App_Resources/Android')) {
webpack.Utils.addCopyRule({
from: '../demo-snippets/App_Resources/Android',
to: webpack.Utils.project.getProjectRootPath() + '/App_Resources/Android'
});
}
if (fs.existsSync('../demo-snippets/App_Resources/iOS')) {
webpack.Utils.addCopyRule({
from: '../demo-snippets/App_Resources/iOS',
to: webpack.Utils.project.getProjectRootPath() + '/App_Resources/iOS'
});
}
webpack.init(env);
const { redirect } = env;
if (snippetConfig) {
snippetConfig(env, webpack);
}
webpack.chainWebpack((config) => {
if (env.fork) {
const coreModulesPackageName = '@akylas/nativescript';
config.resolve.modules
.clear()
.merge([resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules']);
config.resolve.alias.merge({
'@nativescript/core': `${coreModulesPackageName}`,
'tns-core-modules': `${coreModulesPackageName}`
});
}
config.resolve.modules.add(resolve(__dirname, '../demo-snippets/node_modules'));
config.plugin('DefinePlugin').tap((args) => {
if (redirect) {
Object.assign(args[0], {
demoRedirect: JSON.stringify(redirect)
});
} else {
Object.assign(args[0], {
demoRedirect: JSON.stringify('')
});
}
return args;
});
});
return webpack.resolveConfig();
};