@@ -2,85 +2,87 @@ const TerserPlugin = require('terser-webpack-plugin');
22const withCSS = require ( '@zeit/next-css' ) ;
33const resolve = require ( 'resolve' ) ;
44const withMDX = require ( '@next/mdx' ) ( {
5- extension : / \. m d x ? $ / ,
5+ extension : / \. m d x ? $ /
66} ) ;
77const path = require ( 'path' ) ;
88
99const withBundleAnalyzer = require ( '@next/bundle-analyzer' ) ( {
10- enabled : process . env . ANALYZE === 'true' ,
10+ enabled : process . env . ANALYZE === 'true'
1111} ) ;
1212
13- module . exports = withBundleAnalyzer ( withMDX ( withCSS ( {
14- pageExtensions : [ 'js' , 'jsx' , 'md' , 'mdx' ] ,
15- distDir : '../../dist/functions/next' ,
16- webpack : ( config , options ) => {
17- const { dir, isServer } = options ;
18- config . externals = [ ] ;
13+ module . exports = withBundleAnalyzer (
14+ withMDX (
15+ withCSS ( {
16+ pageExtensions : [ 'js' , 'jsx' , 'md' , 'mdx' ] ,
17+ distDir : '../../dist/functions/next' ,
18+ webpack : ( config , options ) => {
19+ const { dir, isServer } = options ;
20+ config . externals = [ ] ;
1921
20- if ( isServer ) {
21- config . externals . push ( ( context , request , callback ) => {
22- resolve (
23- request ,
24- { basedir : dir , preserveSymlinks : true } ,
25- ( err , res ) => {
26- if ( err ) {
27- return callback ( ) ;
28- }
22+ if ( isServer ) {
23+ config . externals . push ( ( context , request , callback ) => {
24+ resolve ( request , { basedir : dir , preserveSymlinks : true } , ( err , res ) => {
25+ if ( err ) {
26+ return callback ( ) ;
27+ }
2928
30- // Next.js by default adds every module from node_modules to
31- // externals on the server build. This brings some undesirable
32- // behaviors because we can't use modules that require CSS files like
33- // `former-kit-skin-pagarme`.
34- //
35- // The lines below blacklist webpack itself (that cannot be put on)
36- if (
37- res . match ( / n o d e _ m o d u l e s [ / \\ ] .* \. j s / ) &&
38- ! res . match ( / n o d e _ m o d u l e s [ / \\ ] w e b p a c k / ) &&
39- ! res . match ( / n o d e _ m o d u l e s [ / \\ ] @ p a t t e r n f l y \/ r e a c t - c o r e / ) &&
40- ! res . match ( / n o d e _ m o d u l e s [ / \\ ] @ p a t t e r n f l y \/ r e a c t - s t y l e s / ) &&
41- ! res . match ( / n o d e _ m o d u l e s [ / \\ ] @ d a t a - d r i v e n - f o r m s / )
42- ) {
43- return callback ( null , `commonjs ${ request } ` ) ;
44- }
29+ // Next.js by default adds every module from node_modules to
30+ // externals on the server build. This brings some undesirable
31+ // behaviors because we can't use modules that require CSS files like
32+ // `former-kit-skin-pagarme`.
33+ //
34+ // The lines below blacklist webpack itself (that cannot be put on)
35+ if (
36+ res . match ( / n o d e _ m o d u l e s [ / \\ ] .* \. j s / ) &&
37+ ! res . match ( / n o d e _ m o d u l e s [ / \\ ] w e b p a c k / ) &&
38+ ! res . match ( / n o d e _ m o d u l e s [ / \\ ] @ p a t t e r n f l y \/ r e a c t - c o r e / ) &&
39+ ! res . match ( / n o d e _ m o d u l e s [ / \\ ] @ p a t t e r n f l y \/ r e a c t - s t y l e s / ) &&
40+ ! res . match ( / n o d e _ m o d u l e s [ / \\ ] @ d a t a - d r i v e n - f o r m s / )
41+ ) {
42+ return callback ( null , `commonjs ${ request } ` ) ;
43+ }
4544
46- callback ( ) ;
47- }
48- ) ;
49- } ) ;
50- }
45+ callback ( ) ;
46+ } ) ;
47+ } ) ;
48+ }
5149
52- config . resolve . alias = {
53- ...config . resolve . alias ,
54- '@docs/raw-component' : path . resolve ( __dirname , './src/components/common/raw-component' ) ,
55- '@docs/doc-components' : path . resolve ( __dirname , './src/doc-components' ) ,
56- '@docs/components' : path . resolve ( __dirname , './src/components' ) ,
57- '@docs/pages' : path . resolve ( __dirname , './pages' ) ,
58- } ;
50+ config . resolve . alias = {
51+ ...config . resolve . alias ,
52+ react : path . resolve ( __dirname , '../../../../node_modules/react' ) ,
53+ 'react-dom' : path . resolve ( __dirname , '../../../../node_modules/react-dom' ) ,
54+ '@docs/raw-component' : path . resolve ( __dirname , './src/components/common/raw-component' ) ,
55+ '@docs/doc-components' : path . resolve ( __dirname , './src/doc-components' ) ,
56+ '@docs/components' : path . resolve ( __dirname , './src/components' ) ,
57+ '@docs/pages' : path . resolve ( __dirname , './pages' )
58+ } ;
5959
60- config . module . rules . push ( {
61- test : / \. ( p n g | j p g | g i f | s v g | e o t | t t f | w o f f | w o f f 2 ) $ / ,
62- use : {
63- loader : 'url-loader' ,
64- options : {
65- limit : 100000 ,
66- } ,
67- } ,
68- } ) ;
69- // Fixes npm packages that depend on `fs` module
70- config . node = {
71- fs : 'empty' ,
72- } ;
60+ config . module . rules . push ( {
61+ test : / \. ( p n g | j p g | g i f | s v g | e o t | t t f | w o f f | w o f f 2 ) $ / ,
62+ use : {
63+ loader : 'url-loader' ,
64+ options : {
65+ limit : 100000
66+ }
67+ }
68+ } ) ;
69+ // Fixes npm packages that depend on `fs` module
70+ config . node = {
71+ fs : 'empty'
72+ } ;
7373
74- config . optimization . minimizer = [
75- new TerserPlugin ( {
76- cache : true ,
77- parallel : false ,
78- terserOptions : {
74+ config . optimization . minimizer = [
75+ new TerserPlugin ( {
76+ cache : true ,
77+ parallel : false ,
78+ terserOptions : {
7979 keep_classnames : true , // eslint-disable-line
8080 keep_fnames : true , // eslint-disable-line
81- } ,
82- } ) ,
83- ] ;
84- return config ;
85- } ,
86- } ) ) ) ;
81+ }
82+ } )
83+ ] ;
84+ return config ;
85+ }
86+ } )
87+ )
88+ ) ;
0 commit comments