1- var extend = require ( 'util' ) . _extend ;
2- var path = require ( 'path' ) ;
3- var webpack = require ( 'webpack' ) ;
4- var TerserPlugin = require ( 'terser-webpack-plugin' ) ;
1+ const extend = require ( 'util' ) . _extend ;
2+ const path = require ( 'path' ) ;
3+ const nodeExternals = require ( 'webpack-node-externals ' ) ;
4+ const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
55
6- var outputPath = path . resolve ( __dirname , 'dist' ) ;
6+ const outputPath = path . resolve ( __dirname , 'dist' ) ;
77
88// Packages that need to be transpiled to ES5
9- var needToTranspile = [ '@rrweb' , 'error-stack-parser-es' ] . join ( '|' ) ;
10- var excludePattern = new RegExp ( 'node_modules/(?!(' + needToTranspile + ')/)' ) ;
9+ const needToTranspile = [ '@rrweb' , 'error-stack-parser-es' ] . join ( '|' ) ;
10+ const excludePattern = new RegExp (
11+ 'node_modules/(?!(' + needToTranspile + ')/)' ,
12+ ) ;
1113
12- var uglifyPlugin = new TerserPlugin ( {
14+ const uglifyPlugin = new TerserPlugin ( {
1315 parallel : true ,
1416} ) ;
1517
16- var snippetConfig = {
18+ const snippetConfig = {
1719 name : 'snippet' ,
1820 entry : {
1921 'rollbar.snippet' : './src/browser/bundles/rollbar.snippet.js' ,
@@ -26,15 +28,15 @@ var snippetConfig = {
2628 module : {
2729 rules : [
2830 {
29- test : / \. j s $ / ,
31+ test : / \. m ? j s $ / ,
3032 loader : 'babel-loader' ,
3133 exclude : [ excludePattern , / v e n d o r / ] ,
3234 } ,
3335 ] ,
3436 } ,
3537} ;
3638
37- var pluginConfig = {
39+ const pluginConfig = {
3840 name : 'plugins' ,
3941 entry : {
4042 jquery : './src/browser/plugins/jquery.js' ,
@@ -55,7 +57,7 @@ var pluginConfig = {
5557 } ,
5658} ;
5759
58- var vanillaConfigBase = {
60+ const vanillaConfigBase = {
5961 entry : {
6062 rollbar : './src/browser/bundles/rollbar.js' ,
6163 } ,
@@ -75,7 +77,7 @@ var vanillaConfigBase = {
7577 } ,
7678} ;
7779
78- var UMDConfigBase = {
80+ const UMDConfigBase = {
7981 entry : {
8082 'rollbar.umd' : [ './src/browser/bundles/rollbar.js' ] ,
8183 } ,
@@ -99,20 +101,42 @@ var UMDConfigBase = {
99101 } ,
100102} ;
101103
102- var noConflictConfigBase = extend ( { } , UMDConfigBase ) ;
104+ const serverCJSConfigBase = {
105+ entry : {
106+ rollbar : './src/server/rollbar.js' ,
107+ } ,
108+ output : {
109+ path : outputPath ,
110+ libraryTarget : 'commonjs2' ,
111+ libraryExport : 'default' ,
112+ } ,
113+ target : 'node' ,
114+ externals : [ nodeExternals ( ) ] ,
115+ module : {
116+ rules : [
117+ {
118+ test : / \. m ? j s $ / ,
119+ loader : 'babel-loader' ,
120+ exclude : [ excludePattern , / v e n d o r / ] ,
121+ } ,
122+ ] ,
123+ } ,
124+ } ;
125+
126+ const noConflictConfigBase = extend ( { } , UMDConfigBase ) ;
103127noConflictConfigBase . entry = {
104128 'rollbar.noconflict.umd' : [ './src/browser/bundles/rollbar.noconflict.js' ] ,
105129} ;
106130
107- var namedAMDConfigBase = extend ( { } , UMDConfigBase ) ;
131+ const namedAMDConfigBase = extend ( { } , UMDConfigBase ) ;
108132namedAMDConfigBase . entry = {
109133 'rollbar.named-amd' : namedAMDConfigBase . entry [ 'rollbar.umd' ] ,
110134} ;
111135namedAMDConfigBase . output = extend ( { } , namedAMDConfigBase . output ) ;
112136namedAMDConfigBase . output . library = 'rollbar' ;
113137namedAMDConfigBase . output . libraryTarget = 'amd' ;
114138
115- var config = [ snippetConfig , pluginConfig ] ;
139+ const config = [ snippetConfig , pluginConfig ] ;
116140
117141function optimizationConfig ( minimizer ) {
118142 return {
@@ -122,7 +146,7 @@ function optimizationConfig(minimizer) {
122146}
123147
124148function addVanillaToConfig ( webpackConfig , filename , extraPlugins , minimizer ) {
125- var vanillaConfig = extend ( { } , vanillaConfigBase ) ;
149+ const vanillaConfig = extend ( { } , vanillaConfigBase ) ;
126150 vanillaConfig . name = filename ;
127151
128152 vanillaConfig . plugins = extraPlugins ;
@@ -135,7 +159,7 @@ function addVanillaToConfig(webpackConfig, filename, extraPlugins, minimizer) {
135159}
136160
137161function addUMDToConfig ( webpackConfig , filename , extraPlugins , minimizer ) {
138- var UMDConfig = extend ( { } , UMDConfigBase ) ;
162+ const UMDConfig = extend ( { } , UMDConfigBase ) ;
139163
140164 UMDConfig . plugins = extraPlugins ;
141165
@@ -152,7 +176,7 @@ function addNoConflictToConfig(
152176 extraPlugins ,
153177 minimizer ,
154178) {
155- var noConflictConfig = extend ( { } , noConflictConfigBase ) ;
179+ const noConflictConfig = extend ( { } , noConflictConfigBase ) ;
156180
157181 noConflictConfig . plugins = extraPlugins ;
158182
@@ -167,7 +191,7 @@ function addNoConflictToConfig(
167191}
168192
169193function addNamedAMDToConfig ( webpackConfig , filename , extraPlugins , minimizer ) {
170- var AMDConfig = extend ( { } , namedAMDConfigBase ) ;
194+ const AMDConfig = extend ( { } , namedAMDConfigBase ) ;
171195
172196 AMDConfig . plugins = extraPlugins ;
173197
@@ -178,11 +202,19 @@ function addNamedAMDToConfig(webpackConfig, filename, extraPlugins, minimizer) {
178202 webpackConfig . push ( AMDConfig ) ;
179203}
180204
205+ function addServerCJSConfigBase ( webpackConfig , filename , minimizer ) {
206+ const serverConfig = extend ( { } , serverCJSConfigBase ) ;
207+ serverConfig . optimization = optimizationConfig ( minimizer ) ;
208+ serverConfig . output = extend ( { filename } , serverCJSConfigBase . output ) ;
209+ webpackConfig . push ( serverConfig ) ;
210+ }
211+
181212function generateBuildConfig ( name , plugins , minimizer ) {
182213 addVanillaToConfig ( config , name , plugins , minimizer ) ;
183214 addUMDToConfig ( config , name , plugins , minimizer ) ;
184215 addNamedAMDToConfig ( config , name , plugins , minimizer ) ;
185216 addNoConflictToConfig ( config , name , plugins , minimizer ) ;
217+ addServerCJSConfigBase ( config , name . replace ( '.js' , '.cjs' ) , minimizer ) ;
186218}
187219
188220generateBuildConfig ( '[name].js' , [ ] ) ;
0 commit comments