@@ -3,17 +3,79 @@ import {
3
3
Configuration ,
4
4
DevServer ,
5
5
SwcJsMinimizerRspackPlugin ,
6
+ SourceMapDevToolPlugin ,
7
+ RspackPluginInstance ,
8
+ RuleSetRule ,
6
9
} from '@rspack/core' ;
7
10
import { merge as rspackMerge } from 'webpack-merge' ;
8
11
import { resolve } from 'path' ;
9
- import { AngularRspackPluginOptions , normalizeOptions } from '../models' ;
12
+ import {
13
+ AngularRspackPluginOptions ,
14
+ normalizeOptions ,
15
+ SourceMap ,
16
+ } from '../models' ;
10
17
import {
11
18
JS_ALL_EXT_REGEX ,
12
19
TS_ALL_EXT_REGEX ,
13
20
} from '@nx/angular-rspack-compiler' ;
14
21
import { getStyleLoaders } from './style-config-utils' ;
15
22
import { getOutputHashFormat } from './helpers' ;
16
23
import { getProxyConfig } from './dev-server-config-utils' ;
24
+ import { DevToolsIgnorePlugin } from '../plugins/tools/dev-tools-ignore-plugin' ;
25
+
26
+ function configureSourceMap ( sourceMap : SourceMap ) {
27
+ const { scripts, styles, hidden, vendor } = sourceMap ;
28
+
29
+ const sourceMapRules : RuleSetRule [ ] = [ ] ;
30
+ const sourceMapPlugins : RspackPluginInstance [ ] = [ ] ;
31
+
32
+ if ( scripts || styles ) {
33
+ const include : RegExp [ ] = [ ] ;
34
+ if ( scripts ) {
35
+ include . push ( / j s $ / ) ;
36
+ }
37
+
38
+ if ( styles ) {
39
+ include . push ( / c s s $ / ) ;
40
+ }
41
+
42
+ sourceMapPlugins . push ( new DevToolsIgnorePlugin ( ) ) ;
43
+
44
+ sourceMapPlugins . push (
45
+ new SourceMapDevToolPlugin ( {
46
+ filename : '[file].map' ,
47
+ include,
48
+ // We want to set sourceRoot to `webpack:///` for non
49
+ // inline sourcemaps as otherwise paths to sourcemaps will be broken in browser
50
+ // `webpack:///` is needed for Visual Studio breakpoints to work properly as currently
51
+ // there is no way to set the 'webRoot'
52
+ sourceRoot : 'webpack:///' ,
53
+ moduleFilenameTemplate : '[resource-path]' ,
54
+ append : hidden ? false : undefined ,
55
+ } )
56
+ ) ;
57
+
58
+ sourceMapRules . push ( {
59
+ test : / \. [ c m ] ? j s x ? $ / ,
60
+ enforce : 'pre' ,
61
+ loader : require . resolve ( 'source-map-loader' ) ,
62
+ options : {
63
+ filterSourceMappingUrl : ( _mapUri : string , resourcePath : string ) => {
64
+ if ( vendor ) {
65
+ // Consume all sourcemaps when vendor option is enabled.
66
+ return true ;
67
+ }
68
+
69
+ // Don't consume sourcemaps in node_modules when vendor is disabled.
70
+ // But, do consume local libraries sourcemaps.
71
+ return ! resourcePath . includes ( 'node_modules' ) ;
72
+ } ,
73
+ } ,
74
+ } ) ;
75
+ }
76
+
77
+ return { sourceMapRules, sourceMapPlugins } ;
78
+ }
17
79
18
80
export async function _createConfig (
19
81
options : AngularRspackPluginOptions ,
@@ -24,15 +86,23 @@ export async function _createConfig(
24
86
const hashFormat = getOutputHashFormat ( normalizedOptions . outputHashing ) ;
25
87
const root = process . cwd ( ) ;
26
88
89
+ const { sourceMapRules, sourceMapPlugins } = configureSourceMap (
90
+ normalizedOptions . sourceMap
91
+ ) ;
92
+
27
93
const defaultConfig : Configuration = {
28
94
context : root ,
29
95
mode : isProduction ? 'production' : 'development' ,
96
+ devtool : normalizedOptions . sourceMap . scripts ? 'source-map' : undefined ,
30
97
output : {
31
98
uniqueName : 'rspack-angular' ,
32
99
publicPath : 'auto' ,
33
100
clean : true ,
34
101
crossOriginLoading : false ,
35
102
trustedTypes : { policyName : 'angular#bundler' } ,
103
+ sourceMapFilename : normalizedOptions . sourceMap . scripts
104
+ ? '[file].map'
105
+ : undefined ,
36
106
} ,
37
107
resolve : {
38
108
extensions : [ '.ts' , '.tsx' , '.mjs' , '.js' ] ,
@@ -57,7 +127,11 @@ export async function _createConfig(
57
127
} ,
58
128
} ,
59
129
rules : [
60
- ...getStyleLoaders ( options . stylePreprocessorOptions ) ,
130
+ ...getStyleLoaders (
131
+ normalizedOptions . stylePreprocessorOptions ,
132
+ normalizedOptions . sourceMap
133
+ ) ,
134
+ ...sourceMapRules ,
61
135
{ test : / [ / \\ ] r x j s [ / \\ ] a d d [ / \\ ] .+ \. j s $ / , sideEffects : true } ,
62
136
{
63
137
test : TS_ALL_EXT_REGEX ,
@@ -92,7 +166,7 @@ export async function _createConfig(
92
166
} ,
93
167
] ,
94
168
} ,
95
- plugins : [ ] ,
169
+ plugins : [ ... sourceMapPlugins ] ,
96
170
} ;
97
171
98
172
const configs : Configuration [ ] = [ ] ;
0 commit comments