1- const { merge } = require ( "webpack-merge" ) ;
2- const { configs } = require ( "@nativescript/webpack/dist/configuration" ) ;
3- const { getPlatformName } = require ( "@nativescript/webpack/dist/helpers/platform" ) ;
4- const { env : _env } = require ( "@nativescript/webpack" ) ;
1+ const webpack = require ( "@nativescript/webpack" ) ;
52
6- /**
7- * @param config {import("webpack-chain").Config}
8- * @param env {import("@nativescript/webpack").IWebpackEnv }
9- * @returns {import("webpack-chain").Config }
10- */
11- module . exports = function ( config , env = _env ) {
12- configs . base ( config , env ) ;
3+ module . exports = ( env ) => {
4+ webpack . init ( env ) ;
135
14- const platform = getPlatformName ( ) ;
15- const mode = env . production ? 'production' : 'development' ;
16- const production = mode === 'production' ;
17-
18- // todo: use env
19- let isAnySourceMapEnabled = true ;
20-
21- config . resolve . extensions . prepend ( '.tsx' ) . prepend ( `.${ platform } .tsx` ) ;
22- config . resolve . alias . set ( 'react-dom' , 'react-nativescript' ) ;
23-
24- config . module
25- . rule ( 'ts' )
26- . test ( [ ...config . module . rule ( 'ts' ) . get ( 'test' ) , / \. t s x $ / ] ) ;
27-
28- config . plugin ( 'DefinePlugin' ) . tap ( ( args ) => {
29- args [ 0 ] = merge ( args [ 0 ] , {
30- /** For various libraries in the React ecosystem. */
31- __TEST__ : false ,
32- /**
33- * Primarily for React Fast Refresh plugin, but technically the allowHmrInProduction option could be used instead.
34- * Worth including anyway, as there are plenty of Node libraries that use this flag.
35- */
36- 'process.env.NODE_ENV' : JSON . stringify ( mode ) ,
37- } ) ;
38-
39- return args ;
40- } ) ;
41-
42- // todo: env flag to forceEnable?
43- config . when ( env . hmr && ! production , ( config ) => {
44- config . module
45- . rule ( 'ts' )
46- . use ( 'babel-loader|react-refresh' )
47- . loader ( 'babel-loader' )
48- . before ( 'ts-loader' )
49- . options ( {
50- sourceMaps : isAnySourceMapEnabled ? 'inline' : false ,
51- babelrc : false ,
52- plugins : [ 'react-refresh/babel' ] ,
53- } ) ;
54-
55- config
56- . plugin ( 'ReactRefreshPlugin' )
57- . use ( require ( '@pmmmwh/react-refresh-webpack-plugin' ) , [
58- {
59- /**
60- * Maybe one day we'll implement an Error Overlay, but the work involved is too daunting for now.
61- * @see https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/79#issuecomment-644324557
62- */
63- overlay : false ,
64- /**
65- * If you (temporarily) want to enable HMR on a production build:
66- * 1) Set `forceEnable` to `true`
67- * 2) Remove the `!production` condition on `tsxRule` to ensure that babel-loader gets used.
68- */
69- forceEnable : false ,
70- } ,
71- ] ) ;
72- } ) ;
73-
74- console . log ( `Webpack 5 config:` , config ) ;
75-
76- return config ;
77- }
6+ return webpack . resolveConfig ( ) ;
7+ } ;
0 commit comments