Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted Asset Management #1305

Merged
merged 11 commits into from
Jun 21, 2017
Merged

Adjusted Asset Management #1305

merged 11 commits into from
Jun 21, 2017

Conversation

TheDutchCoder
Copy link
Collaborator

  • Tried to make the guide as a follow up to Getting Started.
  • Changed some wording and added a lot of output examples, diffs, and sources.

Tried to make the guide as a follow up to `Getting Started`.
Changed some wording and added a lot of output examples, diffs, and sources.
* Update `src/index.js` to not import anything.
* Added missing semi colons
Typo in diff and some style changes
Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good, see my comments. I am a bit worried about how much is being added here but I'm not sure I see a better way. Interested in what the rest of the @webpack/documentation-team thinks.

The problem is that the more detailed things get, the more updates will be required to maintain all of it. For example, the webpack version and output format could quickly become dated (v3 just came out). Though I guess for most of these core features the usage shouldn't change too drastically.

---

So you're all set up with webpack -- transforming and linting your JavaScript modules, generating an html file with the [`HTMLWebpackPlugin`](/plugins/html-webpack-plugin), and even loading some css through your JavaScript modules with the [css-loader](/loaders/css-loader). But wait, your site requires a whole bunch of other assets like images (e.g. `.png`, `.jpg`, `.svg`), fonts (e.g. `.woff`, `.woff2`, `.eot`), and data (e.g. `.json`, `.xml`, `.csv`)!
If you've been following the guides fromt he start, you will now have a small project that shows "Hello webpack", but it would be nice to make it a little more complex by adding a couple of different assets and see how webpack handles these.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/fromt he/from the

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I would change:

... "Hello webpack", but it would be nice to make it a little more complex by adding a couple of different assets and see how webpack handles these.

to something like:

... "Hello webpack". Now let's try to incorporate some other assets, like images, to see how they can be handled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do


``` bash
npm install --save-dev style-loader css-loader
```

Now open your `weback.config.js` file that we created earlier and adjust it so that we can tell webpack to also handle our CSS files.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can leave this line out. The instructions above about adding them to the module configuration should be enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

[8] ./src/index.js 351 bytes {0} [built]
```

Open up `index.html` in your browser again and you should see that `Hello webpack` is now styled in red. If you want to see what webpack did, inspect the page (don't view the page source, as it won't show you the result) and look at the page's head tags. It should contain our style block that we imported in `index.js`:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change:

If you want to see what webpack did, inspect...

to

To see what webpack did, inspect...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<div class="hello">Hello webpack</div>
</body>
</html>
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can drop this example. Instead maybe just mention that the style-loader dynamically inserts <style> blocks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

//...
}
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the empty line (198).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍



## Loading Fonts

So what about other assets like fonts? The file and url loaders will take any file you load through them and output it to your build directory. This means we can use them for any kind of file, including fonts:
So what about other assets like fonts? The file and url loaders will take any file you load through them and output it to your build directory. This means we can use them for any kind of file, including fonts. Let's adjust our `webpack.config.js` file to instruct it to handle font files:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simplify:

Let's adjust our `webpack.config.js` file to instruct it to handle font files:

to

Let's update our `webpack.config.js` to handle font files:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

|- index.html
|- /src
+ |- MyFont.woff
+ |- MyFont.woff2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat nit-picky but I would suggest sticking with lower cased file names so either font.woff/font.woff2 or my-font.woff/my-font.woff2.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do make this change, make sure to change them below as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will do!

|- /node_modules
```

With the loader configured and the fonts in place, you can use the fonts in `@font-face` declarations like you're used to. webpack will automatically serve these files to the loader, just like it did with the images:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite as:

With the loader configured and fonts in place, you can use incorporate them via an `@font-face` declaration. The local `url(...)` directive will be picked up by webpack just as it was with the image:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the trailing newline can be dropped here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 It's my editor taking over ;)



## Loading Data

Another useful asset that can be loaded is data, like JSON files, CSVs, TSVs, and XML. Support for JSON is actually built-in, similar to NodeJS, meaning `import Data from './data.json'` will work by default. To import CSVs, TSVs, and XML you could use the [csv-loader](https://github.com/theplatapi/csv-loader) and [xml-loader](https://github.com/gisikw/xml-loader). Let's handle loading all three:
Another useful asset that can be loaded is data, like JSON files, CSVs, TSVs, and XML. Support for JSON is actually built-in, similar to NodeJS, meaning `import MyData from './data.json'` will work by default. To import CSVs, TSVs, and XML you could use the [csv-loader](https://github.com/theplatapi/csv-loader) and [xml-loader](https://github.com/gisikw/xml-loader). Let's handle loading all three:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, not sure if the variable name change is necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it won't matter probably, I'l revert it.

* Made all requested changes
* Tested `Image` as a variable and changed variable name
* Changed diffs to line up
* Minor tweaks to be more consistent with `Getting Started`
@TheDutchCoder
Copy link
Collaborator Author

@skipjack made all the adjustments and double checked the Image variable (it will produce an error), can you review again? 👍

```

and the relative paths (e.g. `'./font.woff2'`) will be replaced with the final path/filename in your build directory.
Open up `index.html` again and see if our `Hello webpack` text has changed to the new font. If all is well, you should see the changes. Awesome! This is really starting to come together now, isn't it?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can probably drop the last line here:

Awesome! This is really starting to come together now, isn't it?

or at least the Awesome! part, but I'll leave that up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

]
}
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop this trailing line -- maybe we can add something to our linter to flag on these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

```

Now you can `import` any one of those four types of data (JSON, CSV, TSV, XML) and the `Data` variable you import it to will contain parsed JSON for easy consumption:
Now you can `import` any one of those four types of data (JSON, CSV, TSV, XML) and the `MyData` variable you import it to will contain parsed JSON for easy consumption:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't correspond with the line above where Data is used as the variable... I would either drop this change or change them both to MyData.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, completely missed that, should be fixed!

* Changed `MyData` back to `Data`
Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all this looks great -- see the last few comments I added.

* Dropped trailing newline
* Removed some extraneous text
@skipjack
Copy link
Collaborator

Thanks again for your work on this! Will merge soon. Want to tackle output-management.md next? I'll dig into all the code-splitting and lazy load guides this weekend and will ping you for review. I'm also planning to get rid of a few that only have TODOs in them and potentially move one or two (like comparison) out of the /guides. I'm really happy with the way this is progressing and I hope you are too!

@TheDutchCoder
Copy link
Collaborator Author

No problem man, it's a very enjoyable learning experience!

Yeah I'll hop onto Output Management next, I'll probably ping you quite a few times for that one if that's alright. I'll keep the fork until it's ready and then I can submit a PR, should be a bit cleaner as opposed to my patching the PR all the time ;)

I'm certainly happy the way this is going and I hope that beginners will find it easier to follow, which is ultimately our goal as well!

* Removed newline
@TheDutchCoder
Copy link
Collaborator Author

Not sure what the linter failed on tbh. Fixed a new line issue while I was at it.

@skipjack
Copy link
Collaborator

It was some timeouts on hyperlinks -- not anything caused by you. I restarted the build -- we run into that every so often, but it should run ok this time (at least in terms of link testing).

@TheDutchCoder
Copy link
Collaborator Author

Failed again :/

@skipjack
Copy link
Collaborator

Ok don't worry about it, either way I'll get this sorted out. If any testing errors crop up we can always address in a separate PR. Our tests just ping the hell out of img.shields.io currently, we may try to filter those out from our link testing process.

@TheDutchCoder
Copy link
Collaborator Author

Alright cool, I'll await the merge ;)

@skipjack skipjack merged commit 5a5f1a2 into webpack:master Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants