Skip to content

Commit 6a0b7ec

Browse files
committed
part 7d
1 parent a98e870 commit 6a0b7ec

File tree

3 files changed

+127
-168
lines changed

3 files changed

+127
-168
lines changed

src/content/7/en/part7d.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Since part of the imported files are packages like React, Redux, and Axios, the
5353

5454
> The old way of dividing the application's code into multiple files was based on the fact that the <i>index.html</i> file loaded all of the separate JavaScript files of the application with the help of script tags. This resulted in decreased performance, since the loading of each separate file results in some overhead. For this reason, these days the preferred method is to bundle the code into a single file.
5555
56-
Next, we will create a suitable webpack configuration for a React application by hand from scratch.
56+
Next, we will create a webpack configuration by hand, suitable for a new React application.
5757

5858
Let's create a new directory for the project with the following subdirectories (<i>build</i> and <i>src</i>) and files:
5959

@@ -201,7 +201,7 @@ The configuration file has been written in JavaScript and the function returning
201201

202202
Our minimal configuration definition almost explains itself. The [entry](https://webpack.js.org/concepts/#entry) property of the configuration object specifies the file that will serve as the entry point for bundling the application.
203203

204-
The [output](https://webpack.js.org/concepts/#output) property defines the location where the bundled code will be stored. The target directory must be defined as an <i>absolute path</i>, which is easy to create with the [path.resolve](https://nodejs.org/docs/latest-v8.x/api/path.html#path_path_resolve_paths) method. We also use [\_\_dirname](https://nodejs.org/docs/latest/api/globals.html#globals_dirname) which is a variable in Node that stores the path to the current directory.
204+
The [output](https://webpack.js.org/concepts/#output) property defines the location where the bundled code will be stored. The target directory must be defined as an <i>absolute path</i>, which is easy to create with the [path.resolve](https://nodejs.org/docs/latest-v8.x/api/path.html#path_path_resolve_paths) method. We also use [\_\_dirname](https://nodejs.org/docs/latest/api/modules.html#__dirname) which is a variable in Node that stores the path to the current directory.
205205

206206
### Bundling React
207207

@@ -237,7 +237,7 @@ const App = () => {
237237
export default App
238238
```
239239

240-
We still need the <i>build/index.html</i> file that will serve as the "main page" of our application that will load our bundled JavaScript code with a <i>script</i> tag:
240+
We still need the <i>build/index.html</i> file that will serve as the "main page" of our application, which will load our bundled JavaScript code with a <i>script</i> tag:
241241

242242
```html
243243
<!DOCTYPE html>
@@ -353,7 +353,7 @@ It's worth noting that if the bundled application's source code uses <i>async/aw
353353
npm install core-js regenerator-runtime
354354
```
355355

356-
You need to import those dependencies at the top of the <i>index.js</i> file:
356+
You need to import these dependencies at the top of the <i>index.js</i> file:
357357

358358
```js
359359
import 'core-js/stable/index.js'
@@ -370,9 +370,9 @@ By using the configuration from the previous section, we are <i>transpiling</i>
370370

371371
As mentioned in part 1, most browsers do not support the latest features that were introduced in ES6 and ES7, and for this reason, the code is usually transpiled to a version of JavaScript that implements the ES5 standard.
372372

373-
The transpilation process that is executed by Babel is defined with <i>plugins</i>. In practice, most developers use ready-made [presets](https://babeljs.io/docs/plugins/) that are groups of pre-configured plugins.
373+
The transpilation process that is executed by Babel is defined with [plugins](https://babeljs.io/docs/plugins/). In practice, most developers use ready-made [presets](https://babeljs.io/docs/plugins/) that are groups of pre-configured plugins.
374374

375-
Currently, we are using the [@babel/preset-react](https://babeljs.io/docs/plugins/preset-react/) preset for transpiling the source code of our application:
375+
Currently, we are using the [@babel/preset-react](https://babeljs.io/docs/babel-preset-react/) preset for transpiling the source code of our application:
376376

377377
```js
378378
{
@@ -384,7 +384,7 @@ Currently, we are using the [@babel/preset-react](https://babeljs.io/docs/plugin
384384
}
385385
```
386386

387-
Let's add the [@babel/preset-env](https://babeljs.io/docs/plugins/preset-env/) plugin that contains everything needed to take code using all of the latest features and transpile it to code that is compatible with the ES5 standard:
387+
Let's add the [@babel/preset-env](https://babeljs.io/docs/babel-preset-env/) plugin that contains everything needed to take code using all of the latest features and to transpile it to code that is compatible with the ES5 standard:
388388

389389
```js
390390
{
@@ -410,7 +410,7 @@ var App = function App() {
410410
};
411411
```
412412

413-
As we can see, variables are declared with the _var_ keyword as ES5 JavaScript does not understand the _const_ keyword. Arrow functions are also not used, which is why the function definition used the _function_ keyword.
413+
As we can see, variables are declared with the _var_ keyword, as ES5 JavaScript does not understand the _const_ keyword. Arrow functions are also not used, which is why the function definition used the _function_ keyword.
414414

415415
### CSS
416416

@@ -469,9 +469,9 @@ When using CSS, we have to use [css](https://webpack.js.org/loaders/css-loader/)
469469

470470
The job of the [css loader](https://webpack.js.org/loaders/css-loader/) is to load the <i>CSS</i> files and the job of the [style loader](https://webpack.js.org/loaders/style-loader/) is to generate and inject a <i>style</i> element that contains all of the styles of the application.
471471

472-
With this configuration, the CSS definitions are included in the <i>main.js</i> file of the application. For this reason, there is no need to separately import the <i>CSS</i> styles in the main <i>index.html</i> file of the application.
472+
With this configuration, the CSS definitions are included in the <i>main.js</i> file of the application. For this reason, there is no need to separately import the <i>CSS</i> styles in the main <i>index.html</i> file.
473473

474-
If needed, the application's CSS can also be generated into its own separate file by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin).
474+
If needed, the application's CSS can also be generated into its own separate file, by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin).
475475

476476
When we install the loaders:
477477

@@ -483,11 +483,11 @@ The bundling will succeed once again and the application gets new styles.
483483

484484
### Webpack-dev-server
485485

486-
The current configuration makes it possible to develop our application but the workflow is awful (to the point where it resembles the development workflow with Java). Every time we make a change to the code, we have to bundle it and refresh the browser to test the code.
486+
The current configuration makes it possible to develop our application but the workflow is awful (to the point where it resembles the development workflow with Java). Every time we make a change to the code, we have to bundle it and refresh the browser to test it.
487487

488488
The [webpack-dev-server](https://webpack.js.org/guides/development/#using-webpack-dev-server) offers a solution to our problems. Let's install it with the command:
489489

490-
```js
490+
```bash
491491
npm install --save-dev webpack-dev-server
492492
```
493493

@@ -596,7 +596,7 @@ The location of the error indicated in the message does not match the actual loc
596596

597597
Of course, we want to see our actual source code in the error message.
598598

599-
Luckily, fixing the error message in this respect is quite easy. We will ask webpack to generate a so-called [source map](https://webpack.js.org/configuration/devtool/) for the bundle, which makes it possible to <i>map errors</i> that occur during the execution of the bundle to the corresponding part in the original source code.
599+
Luckily, fixing this error message is quite easy. We will ask webpack to generate a so-called [source map](https://webpack.js.org/configuration/devtool/) for the bundle, which makes it possible to <i>map errors</i> that occur during the execution of the bundle to the corresponding part in the original source code.
600600

601601
The source map can be generated by adding a new <i>devtool</i> property to the configuration object with the value 'source-map':
602602

@@ -614,7 +614,7 @@ const config = {
614614
};
615615
```
616616

617-
Webpack has to be restarted when we make changes to its configuration. It is also possible to make webpack watch for changes made to itself but we will not do that this time.
617+
Webpack has to be restarted when we make changes to its configuration. It is also possible to make webpack watch for changes made to itself, but we will not do that this time.
618618

619619
The error message is now a lot better
620620

@@ -644,7 +644,7 @@ When we deploy the application to production, we are using the <i>main.js</i> co
644644

645645
If we inspect the contents of the bundle file, we notice that it could be greatly optimized in terms of file size by removing all of the comments. There's no point in manually optimizing these files, as there are many existing tools for the job.
646646

647-
The optimization process for JavaScript files is called <i>minification</i>. One of the leading tools intended for this purpose is [UglifyJS](http://lisperator.net/uglifyjs/).
647+
The optimization process for JavaScript files is called <i>minification</i>. One of the leading tools intended for this purpose is [UglifyJS](https://github.com/mishoo/UglifyJS/).
648648

649649
Starting from version 4 of webpack, the minification plugin does not require additional configuration to be used. It is enough to modify the npm script in the <i>package.json</i> file to specify that webpack will execute the bundling of the code in <i>production</i> mode:
650650

@@ -674,7 +674,7 @@ $ ls -l build/main.js
674674
-rw-r--r-- 1 mluukkai ATKK\hyad-all 227651 Feb 7 15:58 build/main.js
675675
```
676676

677-
The output of the minification process resembles old-school C code; all of the comments and even unnecessary whitespace and newline characters have been removed, and variable names have been replaced with a single character.
677+
The output of the minification process resembles old-school C code; all of the comments and even unnecessary whitespace and newline characters have been removed, variable names have been replaced with a single character.
678678

679679
```js
680680
function h(){if(!d){var e=u(p);d=!0;for(var t=c.length;t;){for(s=c,c=[];++f<t;)s&&s[f].run();f=-1,t=c.length}s=null,d=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===l||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}a.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)

src/content/7/es/part7c.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ La apariencia de la aplicación resultante se muestra a continuación:
631631

632632
![aplicación de notas con styled components](../../images/7/18ea.png)
633633

634-
Los Styled components han experimentado un crecimiento constante en popularidad en los últimos tiempos, y mucha gente considera que es la mejor forma de definir estilos para las aplicaciones React.
634+
Styled components ha experimentado un crecimiento constante en popularidad en los últimos tiempos, y mucha gente considera que es la mejor forma de definir estilos para las aplicaciones React.
635635

636636
</div>
637637

0 commit comments

Comments
 (0)