-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·3296 lines (3258 loc) · 218 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>React Workflow</title>
<meta name="description" content="How to create a React workflow without create-react-app using webpack.">
<meta name="author" content="Maria D. Campbell">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/blood.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<link rel="stylesheet" href="css/custom.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-background="#ffc600">
<h1>React</h1>
<h2>workflows</h2>
<h4>Without Create-React-App</h4>
<p><small>Second Edition</small></p>
<p>
<small>Created by <a href="https://interglobalmedia.github.io/portfolio/" target="_blank" rel="noopener noreferrer">Maria
D. Campbell</a> / <a href="http://twitter.com/letsbsocial1" target="_blank" rel="noopener noreferrer">@letsbsocial1</a></small>
</p>
</section>
<section data-background="#ffc600">
<h3>About This Presentation</h3>
<p>
This is the <b>second edition</b> of my <b>React Workflows Without CRA</b>. If you want to acquaint yourself with the <b>first edition</b> as well, please visit the <a href="https://github.com/interglobalmedia/react-workflow-presentation"
target="_blank" rel="noopener noreferrer">React
Workflow Presentation</a> repository. For a detailed map of this edition, please visit the <a href="https://github.com/interglobalmedia/react-workflow-updated-2018/tree/e26e04b76a5c1689a7e1c77ee0b9c63734797d01" target="_blank"
rel="noopener noreferrer">README</a> of this edition's repository. To view the
<b><i>source code</i></b> of this <b>workflow</b>, please visit the <a href="https://github.com/interglobalmedia/speech-to-text-app" target="_blank" rel="noopener noreferrer">speech-to-text-app</a> repository.
</p>
</section>
<section data-background="#ffc600">
<h2>Hi There!</h2>
<p class="fragment">
I'm Maria.
</p>
</section>
<section data-background="#ffc600">
<h2>About Me</h2>
<p class="fragment">
I've always been <span class="fragment"><b><i>obsessed</i></b></span> with <span class="fragment"><b><i>development</i></b></span> and <span class="fragment"><b><i>construction</i></b></span> in one way or another.
</p>
</section>
<section data-background="#ffc600">
<h2>Background</h2>
<ul>
<li class="fragment">Fashion design and manufacture.</li>
<li class="fragment">Graphics/production art.</li>
<li class="fragment">Now Fullstack JS, with a focus on React.</li>
</ul>
</section>
<section data-background="#ffc600">
<h1>?</h1>
<p class="fragment">
So why am I here today to discuss <span class="fragment"><b>React workflows</b>?</span>
</p>
</section>
<section data-background="#ffc600">
<h2>Simple.</h2>
<p>
<span class="fragment">When I started learning React,</span> <span class="fragment">I was not happy
with the fact</span> <span class="fragment">that virtually all React learning seemed to revolve</span>
<span class="fragment">around using</span> <span class="fragment"><b><i>create-react-app</i></b></span>
<span class="fragment">to create React applications.</span>
</p>
</section>
<section data-background="#ffc600">
<a href="https://github.com/facebookincubator/create-react-app" target="_blank" rel="noopener noreferrer"><img width="400" height="300" src="images/horse-blinders.jpg" alt="Horse blinders"></a>
<p class="fragment">
And that meant <span class="fragment"><b><i>blindly</i></b></span> accepting its extensive <span class="fragment">boiler-plate.</span>
</p>
</section>
<section data-background="#ffc600">
<img src="images/hiddenman-580x504.jpg" width="480" height="404">
<p>
<span class="fragment">Why <span class="fragment"><b><i>blindly</i></b> ?</span> <span class="fragment">Because
the workflow is <span class="fragment"><b><i>hidden</i></b></span> by default.</span> <span class="fragment">In order to see what is going on,</span> <span class="fragment">you have
to eject out of <span class="fragment"><b><i>CRA</i></b>.</span></span>
</p>
</section>
<section data-background="#ffc600">
<a href="https://unsplash.com/photos/GVFaCidhlhQ" target="_blank" rel="noopener noreferrer"><img src="images/austin-neill-246598.jpg" width="600" height="350"></a>
<p>
<span class="fragment">But once you eject,</span> <span class="fragment"><b><i>THERE IS NO GOING
BACK!</i></b></span>
</p>
</section>
<section data-background="#ffc600">
<img src="images/defyingcertainty.jpg" width="560" height="477">
<p class="fragment">
And one thing I know for sure ...
</p>
</section>
<section data-background="#ffc600" data-background-image="images/deep.jpg" data-background-size="100%" data-background-position="center" data-background-repeat="no-repeat">
<h3>Starting Over</h3>
<p class="fragment" style="background: rgba(250, 235, 215, 0.6)">
<span class="fragment"><b><i>Sometimes</i></b></span> it's faster (and easier) to start from scratch than try to <span class="fragment"><b>manipulate</b></span> to your needs.
</p>
</section>
<section data-background="#ffc600">
<p>
And that's where
</p>
<h1 class="fragment">webpack</h1>
<p class="fragment">
(4 and beyond) come in.
</p>
</section>
<section data-background="#ffc600">
<h1>?</h1>
<p class="fragment">
So why <b><i>webpack </i></b>?
</p>
</section>
<section data-background="#ffc600">
<img class="fragment" width="400" height="300" data-src="images/gulp-grunt.jpg" alt="Grunt vs Gulp">
<p class="fragment">
If done from scratch, it can mean fewer workflow files and lines of code. If you come from task runners like <span class="fragment"><b><i>Gulp</i></b></span> (I do) or <span class="fragment"><b><i>Grunt</i></b>,</span> you know what
I'm talking about.
</p>
</section>
<section data-background="#ffc600">
<a href="https://semaphoreci.com/community/tutorials/testing-common-redux-patterns-in-react-using-ava" target="_blank" rel="noopener noreferrer"><img width="600" height="333" data-src="images/cra.png" alt="Create-React-App"></a>
<p>
<span class="fragment">And if you are familiar with <b><i>CRA</i></b>,</span> <span class="fragment">you
know how extensive its boilerplate is.</span>
</p>
</section>
<section data-background="#ffc600">
<h3>Nothing wrong with that</h3>
<p class="fragment">
if your focus is on writing <span class="fragment"><b><i>JSX</i></b></span> and <span class="fragment"><b><i>JS</i></b></span> for the browser.
</p>
</section>
<section data-background="#ffc600">
<h3>The Problem</h3>
<p class="fragment">
with that approach is that when developers start heavily relying on tools like that, they <b><i>can</i></b> lose site of the bigger picture.
</p>
<ul>
<li class="fragment">
Of how things work.
</li>
<li class="fragment">
Why they work as they do.
</li>
<li class="fragment">
What their options are.
</li>
</ul>
</section>
<section data-background="#ffc600">
<img src="images/homer-internet.jpg" width="640" height="480">
<p>
Which can <b><i class="fragment">STUNT</i></b> one's growth as a developer.
</p>
</section>
<section data-background="#ffc600">
<h2 class="fragment">🐜</h2>
<p>
I first got the bug to create my own custom React workflows when I created my first React application using <b><i>CRA</i></b>.
</p>
</section>
<section data-background="#ffc600" data-background-image="images/blog_MyDebugger2.png" data-background-size="100%" data-background-position="center" data-background-repeat="no-repeat">
<h3>Debugging Difficulties</h3>
<p class="fragment" style="background: rgba(250, 235, 215, 0.6)">
I would get errors in my React projects which I sometimes found difficult to <b><i>debug</i></b>. They might or might not have been <b><i>CRA</i></b> related.
</p>
</section>
<section data-background="#ffc600" data-background-image="images/react-redux-workflow.jpg" data-background-size="cover" data-background-position="center" data-background-repeat="no-repeat">
<h3>Custom React Workflows</h3>
<p class="fragment" style="background: rgba(250, 235, 215, 0.6)">
So I decided to start creating my own React workflows using <b><i>webpack</i></b>.
</p>
</section>
<section data-background="#ffc600">
<h3>What This React Workflow Supports</h3>
<ul>
<li class="fragment">Eslint Configuration for React</li>
<li class="fragment">Jest Testing</li>
<li class="fragment"><b>Bundle Splitting</b> using the <b>SplitChunksPlugin</b></li>
<li class="fragment"><b>Code Splitting</b> using the <b>SplitChunksPlugin</b> and <b>dynamic
imports</b></li>
<li class="fragment">CSS Modules</li>
<li class="fragment">.SCSS</li>
<li class="fragment">Image/File Import</li>
</ul>
</section>
<section data-background="#ffc600">
<h3>What This React Workflow Uses</h3>
<ul>
<li class="fragment">React 16.6.3</li>
<li class="fragment">Webpack 4.3.0</li>
<li class="fragment">Babel 7</li>
<li class="fragment">ESLint 5.9.0</li>
<li class="fragment">Jest 23.6.0</li>
</ul>
</section>
<section data-background="#ffc600">
<p>package.json</p>
<pre class="fragment"><code data-trim>
{
"name": "speech-to-text-app",
"version": "0.0.1",
"private": true,
"description": "\"A voice controlled notes app that allows you to take notes by recording your voice\"",
"main": "index.js",
"scripts": {
"test": "jest",
"lint": "eslint .",
"clean": "rimraf dist",
"cleanSrc": "rimraf dist/src",
"start": "webpack-dev-server --mode development --config config/webpack.base.config.js --open --hot
--history-api-fallback --env.PLATFORM=local --env.VERSION=stag",
"predeploy": "webpack --mode production --config config/webpack.prod.config.js --env.PLATFORM=production
--env.VERSION=stag --progress",
"deploy": "gh-pages -d dist"
},
"jest": {
"setupFiles": [
"raf/polyfill"
],
"moduleNameMapper": {
"\\.(pdf|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|scss)$": "identity-obj-proxy"
}
},
"author": "Maria D. Campbell",
"license": "ISC",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.8",
"@fortawesome/free-brands-svg-icons": "^5.5.0",
"@fortawesome/free-regular-svg-icons": "^5.5.0",
"@fortawesome/free-solid-svg-icons": "^5.5.0",
"@fortawesome/react-fontawesome": "^0.1.3",
"core-js": "^2.5.7",
"gh-pages": "^2.0.1",
"react": "^16.6.3",
"react-dom": "^16.6.3"
},
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"autoprefixer": "^9.3.1",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"clean-webpack-plugin": "^1.0.0",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^1.0.1",
"enzyme": "^3.7.0",
"eslint": "^5.9.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"mini-css-extract-plugin": "^0.4.4",
"node-sass": "^4.10.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"postcss": "^7.0.5",
"postcss-loader": "^3.0.0",
"prop-types": "^15.6.2",
"raf": "^3.4.1",
"react-test-renderer": "^16.6.1",
"regenerator-runtime": "^0.12.1",
"rimraf": "^2.6.2",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"uglifyjs-webpack-plugin": "^2.0.1",
"url-loader": "^1.1.2",
"webpack": "^4.3.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10",
"webpack-manifest-plugin": "^2.0.4",
"webpack-merge": "^4.1.4",
"webpack-visualizer-plugin": "^0.1.11"
}
}
</code></pre>
<p class="fragment">Please ignore the closing <code>rootdir</code> tag at the bottom of the <code>package.json</code>.</p>
</section>
<section data-background="#ffc600">
<h3>What Has Not Changed (Jest)</h3>
<pre class="fragment"><code data-trim>
"jest": {
"setupFiles": [
"raf/polyfill"
],
</code></pre>
<p class="fragment"><b class="fragment">React 16+</b> depends on <span class="fragment"><code>requestAnimationFrame</code>,</span> even in <span class="fragment"><b><i>test
environments</i></b>.</span> First install the <b class="fragment">raf</b> npm package, and then add this to your <span class="fragment"><b>package.json</b>.</span> This was the same in my previous workflow.</p>
</section>
<section data-background="#ffc600">
<h3>What Has Changed (Jest)</h3>
<pre class="fragment"><code data-trim>
"moduleNameMapper": {
"\\.(pdf|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|scss)$": "identity-obj-proxy"
}
</code></pre>
<p class="fragment">
Even though all that has changed here is adding <code class="fragment">|scss</code> to
<span class="fragment"><code>identity-obj-proxy</code>,</span> so much else changed that resulted in the need to add this to the
<code class="fragment">moduleNameMapper</code> property. Again, please ignore the closing <code class="fragment">rootdir</code> tag.
</p>
</section>
<section data-background="#ffc600">
<h3>What Has Not Changed (Jest devDeps)</h3>
<pre class="fragment"><code data-trim>
"babel-jest": "^23.6.0",
"enzyme": "^3.7.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"raf",
"react-test-renderer": "^16.6.1",
"regenerator-runtime": "^0.12.1",
</code></pre>
</section>
<section data-background="#ffc600">
<h3>What Has Changed (Jest DevDeps)</h3>
<pre class="fragment"><code data-trim>
"@babel/core": "^7.1.6",
"babel-core": "^7.0.0-bridge.0",
</code></pre>
<p class="fragment">These packages, along with
<code class="fragment">babel-jest</code> and
<code class="fragment">regenerator-runtime</code> are what is needed now in order to be able to use
<b class="fragment">Jest</b> with
<span class="fragment"><b>Babel 7</b>.</span> To learn more about using <b class="fragment">Babel</b> with <span class="fragment"><b>Jest</b>,</span> please visit
<a href="https://jestjs.io/docs/en/getting-started#using-babel" target="_blank" rel="noopener noreferrer">Using
Babel</a>.
</p>
</section>
<section data-background="#ffc600">
<h3>Configuring Babel 7</h3>
<p class="fragment"><b>everything changed</b></p>
</section>
<section data-background="#ffc600">
<h3>Configuring Babel 7</h3>
<p class="fragment"><b>.babelrc</b></p>
<pre class="fragment"><code data-trim>
{
"presets": ["env", "react", "stage-1", "stage-2", "jest"]
}
</code></pre>
<p class="fragment">Previously, the <b class="fragment">babel config</b> looked something like <b><i>this</i></b>.</p>
</section>
<section data-background="#ffc600">
<h3>Configuring Babel 7</h3>
<p class="fragment"><b>.babelrc</b></p>
<pre class="fragment"><code data-trim>
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-throw-expressions"
]
}
</code></pre>
<p class="fragment"> Now, the <b class="fragment">babel config</b> looks something like <b><i>this</i></b>.</p>
</section>
<section data-background="#ffc600">
<h3>Babel
< 7 Presets</h3>
<p class="fragment">
Before <span class="fragment"><b>Babel 7</b>,</span> proposal plugins were clumped together within their appropriate <span class="fragment"><b><i>presets</i></b>.</span> i.e., <span class="fragment"><b>stage-0</b>,</span>
<span class="fragment"><b>stage-1</b>,</span>
<span class="fragment"><b>stage-2</b>,</span> etc.
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Presets</h3>
<p class="fragment">
<b>.babelrc</b>
</p>
<pre class="fragment"><code data-trim>
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
</code></pre>
<p class="fragment">
With <span class="fragment"><b>Babel 7</b>,</span> presets were removed from the <b class="fragment">webpack</b>
<b class="fragment"><i>config</i></b> and only appear in the <code class="fragment">.babelrc</code> file. Only <b class="fragment">presets</b> which were actually <b class="fragment"><i>approved</i></b> appeared in the
<b class="fragment">presets</b> array.
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Presets</h3>
<pre class="fragment"><code data-trim>
"@babel/preset-env"
</code></pre>
<p class="fragment">
<code class="fragment">"@babel/preset-env"</code> is the <b class="fragment">Babel</b> <b><i>preset</i></b> which allows you to use the <b class="fragment"><i>latest</i></b> <b>JS</b>.
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Presets</h3>
<pre class="fragment"><code data-trim>
"@babel/preset-react"
</code></pre>
<p class="fragment">
<code class="fragment">"@babel/preset-react"</code> is the <b class="fragment">Babel</b> <b><i>preset</i></b> which allows you to use <b class="fragment"><i>React</i></b> code.
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Presets</h3>
<p class="fragment"><b>naming</b></p>
<p class="fragment">
The <b class="fragment"><i>naming</i></b> of <b class="fragment">presets</b> changed with <b class="fragment">Babel
7</b> to differentiate between the versions and maintain naming consistency throughout. Instead of simply adding
<code class="fragment">"env"</code> or <code class="fragment">"react"</code> to the <b>preset array</b>, you now <b><i>have</i></b> to add <code class="fragment">"@babel/preset-env"</code> or <span class="fragment"><code>"@babel/preset-react"</code>,</span> for example.
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Plugins</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
"@babel/plugin-proposal-class-properties": "^7.1.0",
</code></pre>
<p class="fragment">Transforms <b class="fragment">ES6 class syntax</b> into <span class="fragment"><b>ES5
constructor
functions</b>.</span> But the <code class="fragment">class syntax feature</code> has not yet been <span class="fragment"><b><i>approved</i></b>,</span> so it is still called a <span class="fragment"><b><i>proposal</i></b>.</span> With
<span class="fragment"><b>Babel 7</b>,</span> we must add the equivalent
<b class="fragment">Babel
plugin</b> for each <b class="fragment"><i>modern</i></b> <b class="fragment">JS feature</b> we want to implement in our applications. That's because there are no longer <b class="fragment">stage
presets</b> in <span class="fragment"><b>Babel 7</b>.</span></p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Plugins</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
</code></pre>
<p class="fragment">
<b>ES6 modules</b> allow us to import something <b><i>from</i></b> something else:
</p>
<pre class="fragment"><code data-trim>
import * as name from "module-name";
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Plugins</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
"@babel/plugin-proposal-export-namespace-from"
</code></pre>
<p class="fragment">
However, there was <b class="fragment"><i>no</i></b> <span class="fragment"><b>corresponding export</b>!</span>
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Plugins</h3>
<p class="fragment">the <b><i>whys </i></b>contd</p>
<pre class="fragment"><code data-trim>
"@babel/plugin-proposal-export-namespace-from"
</code></pre>
<p class="fragment">
<b>plugin proposal:</b> export namespace from
</p>
<pre class="fragment"><code data-trim>
export * as ns from "mod";
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Plugins</h3>
<p class="fragment">the <b><i>whys </i></b>contd</p>
<pre class="fragment"><code data-trim>
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
</code></pre>
<p class="fragment"><b>example:</b></p>
<pre class="fragment"><code data-trim>
function test(param = throw new Error('required!')) {
const test = param === true || throw new Error('Falsey!');
}
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Plugins</h3>
<p class="fragment">the <b><i>whys </i></b>contd</p>
<pre class="fragment"><code data-trim>
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
</code></pre>
<p class="fragment">
<code class="fragment">import()</code> returns a <span class="fragment"><b><i>promise</i></b>,</span> so it can be used with
<span class="fragment"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function"
target="_blank" rel="noopener noreferrer">async functions</a>.</span> However, doing this
<b class="fragment"><i>requires</i></b> the
<code class="fragment">"@babel/plugin-syntax-dynamic-import"</code>
<b>plugin</b> in <span class="fragment"><b>Webpack</b>.</span>
</p>
</section>
<section data-background="#ffc600">
<h3>Configuring Babel 7</h3>
<p class="fragment"><b>config/webpack.base.config.js</b></p>
<pre class="fragment"><code data-trim>
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
</code></pre>
<p class="fragment">Now <code class="fragment">.JS$ rules</code> looks like <b><i>this</i></b>. No more
<span class="fragment"><b><i>presets</i></b>.</span> Only in <span class="fragment"><b>.babelrc</b>.</span> In addition, I changed the name of the <b class="fragment"><i>webpack config</i></b> file. I will talk about that later.</p>
</section>
<section data-background="#ffc600">
<h3>JS$ test property</h3>
<pre class="fragment"><code data-trim>
test: /\.js$/,
</code></pre>
<p class="fragment">
The <span class="fragment"><code class="fragment">test</code></span> property tells webpack what kind of file to match to the
<span class="fragment"><code>babel-loader</code>.</span> The regex <span class="fragment"><code>/\.js$/</code></span> refers to any extension that matches
<span class="fragment"><code>.js</code></span> at the end of a filename.</span>
</p>
</section>
<section data-background="#ffc600">
<h3>Exclude Property</h3>
<pre class="fragment"><code data-trim>
exclude: /node_modules/,
</code></pre>
<p class="fragment">
The <span class="fragment"><code>exclude</code></span> property means that whatever modules match the <span class="fragment"><code>/node_modules/</code></span> regex should be excluded from <span class="fragment"><code>bundle.js</code>.</span>
</p>
</section>
<section data-background="#ffc600">
<h3>JS$ use property</h3>
<pre class="fragment"><code data-trim>
use: {
loader: 'babel-loader',
},
</code></pre>
<p class="fragment">
Then it <code class="fragment">uses</code> that loader to transform those files before adding it to
<span class="fragment"><code>bundle.js</code>.</span>
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Packages</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
@babel/core
</code></pre>
<p class="fragment">This is the <b>Babel</b> core <span class="fragment"><b><i>compiler</i></b>.</span> It makes it possible to use <span class="fragment"><code>babel-loader</code>.</span> Most <b class="fragment">babel
plugins/top level packages</b> have a <b class="fragment"><i>peerDependency</i></b> on
<span class="fragment"><b>@babel/core</b>.</span> Previously it had been <span class="fragment"><b>babel-core</b>.</span> It is also needed for
<span class="fragment"><b>Jest</b>.</span> To learn more about
<a class="fragment" href="https://nodejs.org/en/blog/npm/peer-dependencies/" target="_blank" rel="noopener noreferrer">peerDependencies,</a> click <span class="fragment"><a href="https://nodejs.org/en/blog/npm/peer-dependencies/" target="_blank"
rel="noopener noreferrer">here</a>.</span></p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Packages</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
"babel-core": "^7.0.0-bridge.0"
</code></pre>
<p class="fragment">This package is needed for <b class="fragment">Jest</b> testing if <b class="fragment">Babel
7</b> is being used. This package is meant to <b class="fragment">ease</b> the <b class="fragment"><i>transition</i></b> libraries that use "babel-core" as a
<b class="fragment"><i>peerDependency</i></b> for <span class="fragment"><b>Babel 6</b>.</span> To learn more, please visit the
<span class="fragment"><a href="https://github.com/babel/babel-bridge" target="_blank" rel="noopener noreferrer">babel-bridge
repo
</a>.</span></p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Packages</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
"@babel/polyfill": "^7.0.0"
</code></pre>
<p class="fragment"><b>React 16+</b> depends on collection types <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" target="_blank" rel="noopener noreferrer">Map</a> and
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" target="_blank" rel="noopener noreferrer">Set</a>.
<a href="https://babeljs.io/docs/en/babel-polyfill/" target="_blank" rel="noopener noreferrer">@babel/polyfill</a>
<b><i>emulates</i></b> a <b><i>full</i></b> <b>ES2015+ environment</b> and is for <b>applications</b>. You can use <b>built-ins</b> like <b>Promise</b> or <b>WeakMap</b>, static methods like
<b>Array.from</b> or <b>Object.assign</b>, instance methods like <b>Array.prototype.includes</b>, and <b>generator functions</b> provided you use the
<b>regenerator plugin</b>.
</p>
</section>
<section data-background="#ffc600">
<h3>Babel 7 Packages</h3>
<p class="fragment">the <b><i>whys</i></b></p>
<pre class="fragment"><code data-trim>
"@babel/register": "^7.0.0",
</code></pre>
<p class="fragment">Allows you to use the <b class="fragment">require module</b> in your applications.</p>
</section>
<section data-background="#ffc600">
<h3>Configuring ESLint</h3>
<p class="fragment"><b>package.json</b></p>
<pre class="fragment"><code data-trim>
"babel-eslint": "^10.0.1",
"eslint": "^5.9.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-react": "^7.11.1",
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Configuring ESLint</h3>
<p class="fragment"><b>.eslintrc.json</b></p>
<pre class="fragment"><code data-trim>
{
"parser": "babel-eslint",
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"jest": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:import/recommended"],
"settings": {
"react": {
"pragma": "React",
"version": "16.6.3"
}
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"import",
"react"
],
"rules": {
"no-unused-vars": 0,
"no-console": 0,
"max-len": [1, 120, 2, {
"ignoreComments": true
}],
"prop-types": [0],
"indent": [
0
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
0
],
"semi": [
0
]
}
}
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Configuring ESLint</h3>
<p class="fragment"><b>config/webpack.base.config.js</b></p>
<pre class="fragment"><code data-trim>
{
test: /\.js$/,
exclude: /node_modules/,
loaders: [
'babel-loader',
'eslint-loader'
]
},
</code></pre>
<p class="fragment">For my complete write up on <b>configuring ESLint with React</b>, please visit
<a href="http://www.mariadcampbell.com/2018/11/19/the-importance-of-eslint-and-react/" target="_blank" rel="noopener noreferrer">The
Importance Of ESlint (And React)
</a>. To view the complete <b>webpack.base.config.js</b> file, click
<a href="https://github.com/interglobalmedia/speech-to-text-app/blob/master/config/webpack.base.config.js" target="_blank" rel="noopener noreferrer">
here
</a>.
</p>
</section>
<section data-background="#ffc600">
<h3>Configuring Webpack</h3>
<p class="fragment"><b>much changed</b></p>
</section>
<section data-background="#ffc600">
<h3>Configuring Webpack</h3>
<p class="fragment">
I still have <b><i>two</i></b> webpack <b>config</b> files, but now they reside in a <b>config</b>
<b><i>folder</i></b> and are also named differently.
</p>
<p class="fragment">
One file is called <code class="fragment">webpack.base.config.js</code> and is for webpack <b>configs</b> related to the <b><i>development</i></b> environment, some of which also are related to <b><i>production</i></b>. The other is
<code class="fragment">webpack.prod.config.js</code> and is for webpack <b>configs</b> related <b><i>only</i></b> to the <b><i>production</i></b> environment.
</p>
</section>
<section data-background="#ffc600" data-background-image="images/dog-cloning.jpg" data-background-size="cover" data-background-position="center" data-background-repeat="no-repeat">
<h3>Configuring Webpack</h3>
<p class="fragment"><b>why the new configs</b></p>
<p class="fragment" style="background: rgba(250, 235, 215, 0.7)">Setting up <b>Webpack</b> with these two <b><i>new configs</i></b> means <b><i>drier</i></b> code. No <b><i>duplications</i></b> as before. Click <a href="https://github.com/interglobalmedia/portfolio" target="_blank" rel="noopener noreferrer">here</a> to visit a <b>repo</b> containing my <b><i>previous</i></b> <b>workflow</b>.
</p>
</section>
<section data-background="#ffc600">
<h3>Configuring Webpack</h3>
<p><b>what requires/variables have NOT changed (base config)</b></p>
<pre class="fragment"><code data-trim>
const path = require('path');
const webpack = require('webpack');
</code></pre>
<p class="fragment">As you can see, not much!</p>
</section>
<section data-background="#ffc600">
<h3>Configuring Webpack</h3>
<p class="fragment"><b>what requires/variables have changed (base config)</b></p>
<pre class="fragment"><code data-trim>
const CopyWebpackPlugin = require('copy-webpack-plugin');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Configuring Webpack</h3>
<p class="fragment"><b>how module.exports has changed (base config)</b></p>
<pre class="fragment"><code data-trim>
module.exports = env => {
const {PLATFORM, VERSION} = env;
return merge([
{
entry: {
main: './src/index.js'
},
output: {
filename: PLATFORM === 'production' ? 'scripts/[name].[contenthash].chunk.js' : 'scripts/[name].chunk.js',
chunkFilename: PLATFORM === 'production' ? 'scripts/[name].[contenthash].chunk.js' : 'scripts/[name].chunk.js',
path: path.resolve(__dirname, '../dist')
},
optimization: {
splitChunks: {
chunks: 'all'
}
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loaders: [
'babel-loader',
'eslint-loader'
]
},
{
test: /\.(scss|sass|css)$/,
exclude: /node_modules/,
loaders: [
PLATFORM === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]'
},
},
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(jpg|png|gif|svg|pdf|ico)$/,
use: [{
loader: 'file-loader',
options: {
name: '[path][name].[hash:8].[ext]'
},
}],
},
]
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: 'src/index.html',
favicon: 'src/favicon.ico', /* remove */
styles: 'src/styles.css',
inject: true
}),
new MiniCssExtractPlugin({
filename: PLATFORM === 'production' ? 'styles/[name].[hash].css' : '[name].css',
}),
new CopyWebpackPlugin([{
from: 'src/static'
}]),
new WorkboxPlugin.GenerateSW({
swDest: 'sw.js'
}),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(env.VERSION),
'process.env.PLATFORM': JSON.stringify(env.PLATFORM)
})
],
},
])
}
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Configuring Webpack</h3>
<p class="fragment"><b>config/webpack.base.config.js</b></p>
<pre class="fragment"><code data-trim>
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
module.exports = env => {
const {PLATFORM, VERSION} = env;
return merge([
{
entry: {
main: './src/index.js'
},
output: {
filename: PLATFORM === 'production' ? 'scripts/[name].[contenthash].chunk.js' : 'scripts/[name].chunk.js',
chunkFilename: PLATFORM === 'production' ? 'scripts/[name].[contenthash].chunk.js' : 'scripts/[name].chunk.js',
path: path.resolve(__dirname, '../dist')
},
optimization: {
splitChunks: {
chunks: 'all'
}
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loaders: [
'babel-loader',
'eslint-loader'
]
},
{
test: /\.(scss|sass|css)$/,
exclude: /node_modules/,
loaders: [
PLATFORM === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]'
},
},
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(jpg|png|gif|svg|pdf|ico)$/,
use: [{
loader: 'file-loader',
options: {
name: '[path][name].[hash:8].[ext]'
},
}],
},
]
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: 'src/index.html',
favicon: 'src/favicon.ico', /* remove */
styles: 'src/styles.css',
inject: true
}),
new MiniCssExtractPlugin({
filename: PLATFORM === 'production' ? 'styles/[name].[hash].css' : '[name].css',
}),
new CopyWebpackPlugin([{
from: 'src/static'
}]),
new WorkboxPlugin.GenerateSW({
swDest: 'sw.js'
}),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(env.VERSION),
'process.env.PLATFORM': JSON.stringify(env.PLATFORM)
})
],
},
])
}
</code></pre>
</section>
<section data-background="#ffc600">
<h3>Dependency Graph</h3>
<p class="fragment">
When <b><i>webpack</i></b> processes your app, it <b class="fragment"><i>recursively</i></b> <b class="fragment">builds</b> a <span class="fragment"><code>dependency
graph</code></span> that <b class="fragment"><i>includes</i></b> every <b class="fragment">module</b> that your app <span class="fragment"><b><i>needs</i></b>,</span> and then <b class="fragment"><i>packages</i></b> all of
those <b class="fragment">modules</b> into a small number of
<b class="fragment"><i>bundles</i></b> to be <b class="fragment">loaded</b> by the
<span class="fragment"><b>browser</b>.</span>
</p>
</section>
<section data-background="#ffc600">
<h3>webpack basics</h3>
<p class="fragment">
To get started, you only need to understand 4 basic concepts:
</p>
<ul>
<li class="fragment">
Entry
</li>
<li class="fragment">
Output
</li>
<li class="fragment">
Loaders
</li>
<li class="fragment">
Plugins
</li>
</ul>
</section>
<section data-background="#ffc600">
<h3>entry</h3>
<pre class="fragment"><code data-trim>
module.exports = {
entry: {
main: './src/index.js'
},
}
</code></pre>
<p class="fragment">
The starting point of <b><i>webpack</i></b>'s <b class="fragment">dependency graph</b> is called the <span class="fragment"><code>entry