-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
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
There was a problem hiding this 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.
content/guides/asset-management.md
Outdated
--- | ||
|
||
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
content/guides/asset-management.md
Outdated
|
||
``` 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. | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
content/guides/asset-management.md
Outdated
[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`: |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
content/guides/asset-management.md
Outdated
<div class="hello">Hello webpack</div> | ||
</body> | ||
</html> | ||
``` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
content/guides/asset-management.md
Outdated
//... | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
content/guides/asset-management.md
Outdated
|
||
|
||
## 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: |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
content/guides/asset-management.md
Outdated
|- index.html | ||
|- /src | ||
+ |- MyFont.woff | ||
+ |- MyFont.woff2 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, will do!
content/guides/asset-management.md
Outdated
|- /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: |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
content/guides/asset-management.md
Outdated
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
content/guides/asset-management.md
Outdated
|
||
|
||
## 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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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`
@skipjack made all the adjustments and double checked the |
* Changed `component ()` to `component()`
content/guides/asset-management.md
Outdated
``` | ||
|
||
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? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
content/guides/asset-management.md
Outdated
] | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
content/guides/asset-management.md
Outdated
``` | ||
|
||
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: |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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`
There was a problem hiding this 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
Thanks again for your work on this! Will merge soon. Want to tackle |
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
Not sure what the linter failed on tbh. Fixed a new line issue while I was at it. |
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). |
Failed again :/ |
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. |
Alright cool, I'll await the merge ;) |
Getting Started
.