Repository navigation
Expand file tree
/
Copy pathnativescript.webpack.js
More file actions
86 lines (78 loc) · 2.43 KB
/
Copy pathnativescript.webpack.js
File metadata and controls
86 lines (78 loc) · 2.43 KB
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
const path = require('path');
const {
getPlatformName,
} = require('@nativescript/webpack/dist/helpers/platform');
// Solid 2 publishes an exports map whose `node` condition points at the SSR
// build. Resolving through it leaves the app with a renderer that never applies
// updates, so every entry point is pinned to an explicit browser bundle. `$`
// keeps each alias exact so subpaths still resolve normally.
const solidAliases = (production) => {
const solidDist = path.join(
path.dirname(require.resolve('solid-js/package.json')),
'dist'
);
const signalsDist = path.join(
path.dirname(require.resolve('@solidjs/signals/package.json')),
'dist'
);
const universalDist = path.dirname(require.resolve('@solidjs/universal'));
return {
'solid-js$': path.join(solidDist, production ? 'solid.js' : 'solid.dev.js'),
'@solidjs/signals$': path.join(
signalsDist,
production ? 'prod/index.js' : 'dev.js'
),
'@solidjs/universal$': path.join(
universalDist,
production ? 'universal.js' : 'universal.dev.js'
),
};
};
const solid = (config, env) => {
const platform = getPlatformName();
config.resolve.extensions
.prepend('.js')
.prepend('.ts')
.prepend('.tsx')
.prepend('.jsx')
.prepend(`.${platform}.js`)
.prepend(`.${platform}.ts`)
.prepend(`.${platform}.jsx`)
.prepend(`.${platform}.tsx`);
const aliases = solidAliases(env.production);
for (const [key, value] of Object.entries(aliases)) {
config.resolve.alias.set(key, value);
}
config.module
.rule('bundle-source')
.test(/\.(|t|j)sx?$/)
.exclude.add(/node_modules/)
.end()
.use('babel-loader')
.loader('babel-loader')
.before('ts-loader')
.options({
babelrc: false,
configFile: false,
presets: ['@babel/typescript'],
plugins: [
path.resolve(__dirname, 'babel-plugin-native-class.js'),
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
[
'@solidjs/babel-plugin',
{
moduleName: '@nativescript-community/solid-js',
generate: 'universal',
hydratable: false,
},
],
],
});
if (!env.production) {
config.output.devtoolNamespace('app');
config.devServer.hotOnly(true);
config.devServer.hot(true);
}
};
module.exports = webpack => webpack.chainWebpack(solid);