@@ -6,15 +6,29 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
66const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' ) ;
77const ForkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
88const ReactRefreshWebpackPlugin = require ( '@pmmmwh/react-refresh-webpack-plugin' ) ;
9+ const { sentryWebpackPlugin } = require ( '@sentry/webpack-plugin' ) ;
910const { glob } = require ( 'glob' ) ;
1011const path = require ( 'path' ) ;
1112
1213export type WebpackPluginDefinition = undefined | null | false | '' | 0 | ( ( this : Compiler , compiler : Compiler ) => void ) | WebpackPluginInstance ;
1314
15+ export interface SentryConfig {
16+ org : string ;
17+ project : string ;
18+ release ?: string ;
19+ urlPrefix ?: string ;
20+ include ?: string ;
21+ ignore ?: string [ ] ;
22+ inject ?: boolean ;
23+ cleanArtifacts ?: boolean ;
24+ rewrite ?: boolean ;
25+ }
26+
1427export interface CreatePluginsOptions extends CommonConfigOptions {
1528 generateSourceMaps ?: boolean ;
1629 plugins ?: WebpackPluginDefinition [ ] ;
1730 definePlugin ?: Record < string , any > ;
31+ initSentry ?: SentryConfig ;
1832}
1933
2034export const createPlugins = ( {
@@ -26,6 +40,7 @@ export const createPlugins = ({
2640 _unstableHotReload,
2741 hotReload,
2842 useFileHash = true ,
43+ initSentry,
2944} : CreatePluginsOptions ) => {
3045 if ( ! rootFolder ) {
3146 fecLogger ( LogType . error , 'rootFolder is required attribute for the createPlugins function!' ) ;
@@ -68,6 +83,31 @@ export const createPlugins = ({
6883 ...( hasTsConfig ? [ new ForkTsCheckerWebpackPlugin ( ) ] : [ ] ) ,
6984 ...( plugins || [ ] ) ,
7085 ...( internalHotReload ? [ new ReactRefreshWebpackPlugin ( ) ] : [ ] ) ,
86+ // Put the sentry plugin at the end of the plugins array
87+ ...( process . env . ENABLE_SENTRY && initSentry
88+ ? [
89+ sentryWebpackPlugin ( {
90+ ...( process . env . SENTRY_AUTH_TOKEN && {
91+ authToken : process . env . SENTRY_AUTH_TOKEN ,
92+ } ) ,
93+ org : initSentry . org ,
94+ project : initSentry . project ,
95+ release : process . env . SENTRY_RELEASE ,
96+ urlPrefix : initSentry . urlPrefix ,
97+ include : initSentry . include ,
98+ ignore : initSentry . ignore ,
99+ inject : initSentry . inject ,
100+ cleanArtifacts : initSentry . cleanArtifacts ,
101+ rewrite : initSentry . rewrite ,
102+ moduleMetadata : ( { release } : { release : string } ) => ( {
103+ dsn : process . env . SENTRY_DSN ,
104+ org : initSentry . org ,
105+ project : initSentry . project ,
106+ release,
107+ } ) ,
108+ } ) ,
109+ ]
110+ : [ ] ) ,
71111 ] ;
72112} ;
73113
0 commit comments