Skip to content

Commit 7431c89

Browse files
committed
Begin work on docs refresh
1 parent 29a5d4a commit 7431c89

File tree

5 files changed

+99
-143
lines changed

5 files changed

+99
-143
lines changed

docs/faq.md

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,47 @@
22

33
### Does this tool require that I use Laravel?
44

5-
No. It has a few optimizations for Laravel, but it can be used for any project.
6-
7-
### My code isn't being minified.
8-
9-
Minification will only be performed, when your `NODE_ENV` is set to _production_. Not only will this speed up your compilation time, but it's also unnecessary during development. Here's an example of running webpack for production.
10-
11-
```bash
12-
export NODE_ENV=production && webpack --progress --hide-modules
13-
```
14-
15-
It's highly recommended that you add the following NPM scripts to your `package.json` file. Please note that Laravel includes these out of the box.
5+
No. It has awareness of Laravel, but it can be used for any project. Just be sure to explicitly set the path to your project's `public` or `dist` directory, like so:
166

177
```js
18-
"scripts": {
19-
"dev": "NODE_ENV=development webpack --progress --hide-modules",
20-
"watch": "NODE_ENV=development webpack --watch --progress --hide-modules",
21-
"hot": "NODE_ENV=development webpack-dev-server --inline --hot",
22-
"production": "NODE_ENV=production webpack --progress --hide-modules"
23-
},
8+
mix.setPublicPath('dist');
249
```
2510

26-
### I'm using a VM, and webpack isn't picking up my file changes.
27-
28-
If you're running `npm run dev` through a VM, you may find that file changes are not picked up by webpack. If that's the case, there are two ways to resolve this:
11+
This tells Mix the basic directory where all of your assets should be compiled to.
2912

30-
1. Configure webpack to **poll** the filesystem for changes _Note: Polling the filesystem is resource-intensive and will likely shorten battery life on the go._
31-
2. **Forward** file change notifications to the VM by using something like [vagrant-fsnotify](https://github.com/adrienkohlbecker/vagrant-fsnotify). _Note, this is a [Vagrant](https://www.vagrantup.com)-only plugin._
13+
### My code isn't being minified.
3214

33-
To **poll** the VM's filesystem, update your NPM script to use the `--watch-poll` flag, in addition to the `--watch` flag. Like this:
15+
Minification will only be performed when your `NODE_ENV` is set to _production_. By default, this mode is set to development.
3416

35-
```js
36-
"scripts": {
37-
"watch": "NODE_ENV=development webpack --watch --watch-poll",
38-
 }
17+
```bash
18+
npx mix
3919
```
4020

41-
To **forward** file change notifications to the VM, simply install [vagrant-fsnotify](https://github.com/adrienkohlbecker/vagrant-fsnotify) on the host machine:
21+
If you're ready to build for a production environment, add the `--production` flag, like so:
4222

4323
```bash
44-
vagrant plugin install vagrant-fsnotify
24+
npx mix --production
4525
```
4626

47-
Now you may [configure](https://github.com/adrienkohlbecker/vagrant-fsnotify#basic-setup) vagrant to use the plugin. In [Homestead](https://laravel.com/docs/5.4/homestead), your `Homestead.yaml` file would look something like this:
48-
49-
```yaml
50-
folders:
51-
- map: /Users/jeffrey/Code/laravel
52-
to: /home/vagrant/Code/laravel
53-
options:
54-
fsnotify: true
55-
exclude:
56-
- node_modules
57-
- vendor
58-
```
27+
### I'm using a VM, and webpack isn't picking up my file changes.
5928

60-
Once your vagrant machine is started, simply run `vagrant fsnotify` on the host machine to forward all file changes to the VM. You may then run `npm run watch` inside the VM and have your changes automatically picked up.
29+
If you're running `npx mix` through a VM, you may find that file changes are not picked up by webpack. If that's the case, consider configuring webpack to **poll** your filesystem for changes, like so:
6130

62-
If you're still having trouble, [see here for additional troubleshooting tips](https://webpack.github.io/docs/troubleshooting.html#webpack-doesn-t-recompile-on-change-while-watching).
31+
```js
32+
npx mix watch --poll
33+
```
6334

6435
### Why is it saying that an image in my CSS file can't be found in `node_modules`?
6536

66-
Let's imagine that you have a relative path to an asset that doesn't exist in your `resources/assets/sass/app.scss` file.
37+
Imagine that you have a relative path to an asset that doesn't exist in your `resources/sass/app.scss` file.
6738

6839
```css
6940
body {
7041
background: url('../img/example.jpg');
7142
}
7243
```
7344

74-
When referencing a relative path, always think in terms of the current file. As such, webpack will look for `resources/assets/img/example.jpg`. If it can't find it, it'll then begin searching for the file location, including within `node_modules`. If it still can't be found, you'll receive the error:
45+
When referencing a relative path, always think in terms of the current file. As such, webpack will look one level up for `resources/assets/img/example.jpg`. If it can't find it, it'll then begin searching for the file location, including within the massive `node_modules` directory. If it still can't be found, you'll receive the error:
7546

7647
```
7748
ERROR Failed to compile with 1 errors
@@ -95,11 +66,11 @@ This is particularly useful for legacy projects where your folder structure is a
9566

9667
### My mix-manifest.json file shouldn't be in the project root.
9768

98-
If you're not using Laravel, your `mix-manifest.json` file will be dumped into the project root. If you need to change this, call `mix.setPublicPath('dist/');`, and your manifest file will now be saved in that base directory.
69+
If you're not using Laravel, your `mix-manifest.json` file will be dumped into the project root. If you need to change this, call `mix.setPublicPath('dist/');`, and your manifest file will now correctly be saved to the `dist` directory.
9970

100-
### How Do I autoload modules with webpack?
71+
### Can I autoload modules with Mix and webpack?
10172

102-
Through its `ProvidePlugin` plugin, webpack allows you to automatically load modules, where needed. A common use-case for this is when we need to pull in jQuery.
73+
Yes. Through its `ProvidePlugin` plugin, webpack allows for this very functionality. A common use-case for this is when we need jQuery to be available to all of your modules. Here's a webpack-specific example of how you might accomplish this.
10374

10475
```js
10576
new webpack.ProvidePlugin({
@@ -113,7 +84,7 @@ jQuery('#item'); // <= just works
11384
// $ is automatically set to the exports of module "jquery"
11485
```
11586

116-
While Laravel Mix automatically loads jQuery for you (exactly as the example above demonstrates), should you need to disable it (by passing an empty object), or override it with your own modules, you may use the `mix.autoload()` method. Here's an example:
87+
Of course, Mix provides an API on top of webpack to make this sort of autoloading a cinch.
11788

11889
```js
11990
mix.autoload({
@@ -122,6 +93,8 @@ mix.autoload({
12293
});
12394
```
12495

96+
Above, we're effectively saying, "When webpack comes across the `$` or `window.jQuery` or `jQuery` symbols, replace it with the exported jQuery module."
97+
12598
### Why am I seeing a "Vue packages version mismatch" error?
12699

127100
If, upon updating your dependencies, your compile fails with the message:
@@ -135,7 +108,7 @@ Vue packages version mismatch:
135108
136109
```
137110

138-
This means your `vue` and `vue-template-compiler` dependencies are out of sync. Per Vue's instructions, the version number for both of these dependencies must be identical. Update as needed to fix the problem:
111+
This means your `vue` and `vue-template-compiler` dependencies are out of sync. Per Vue 2's instructions, the version number for both of these dependencies must be identical. Update as needed to fix the problem:
139112

140113
```
141114
npm update vue
@@ -144,3 +117,17 @@ npm update vue
144117
145118
npm install [email protected]
146119
```
120+
121+
### I'm having trouble updating/installing Mix.
122+
123+
Unfortunately, there are countless reasons why your dependencies may not be installing properly. A common root relates to an ancient version of Node (`node -v`) and npm (`npm -v`) installed. As a first step, visit http://nodejs.org and update those.
124+
125+
Otherwise, often, it's related to a faulty lock file that needs to be deleted. Give this series of commands a try to install everything from scratch:
126+
127+
```bash
128+
rm -rf node_modules
129+
rm package-lock.json yarn.lock
130+
npm cache clear --force
131+
npm install
132+
``
133+
```

docs/installation.md

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
# Installation
22

3-
Though Laravel Mix is optimized for Laravel usage, it may be used for any type of application.
3+
Though Laravel Mix was originally built for Laravel projects, it of course may be used for any type of application.
44

5-
### Laravel Project
5+
### Stand-Alone Projects
66

7-
Laravel ships with everything you need to get started. Simply:
8-
9-
- Install Laravel
10-
- Run `npm install`
11-
- Visit your `webpack.mix.js file`, and get started!
12-
13-
Now, from the command line, you may run `npm run watch` to watch your files for changes, and then recompile.
14-
15-
> Note: You won't find a `webpack.config.js` file in your project root. By default, Laravel defers to the config file from this repo. However, should you need to configure it, you may copy the file to your project root, and then update your `package.json` NPM scripts accordingly: `cp node_modules/laravel-mix/setup/webpack.config.js ./`.
16-
17-
### Stand-Alone Project
18-
19-
Begin by installing Laravel Mix through NPM or Yarn, and then copying the example Mix file to your project root.
7+
Begin by installing Laravel Mix through NPM or Yarn.
208

219
```bash
2210
mkdir my-app && cd my-app
2311
npm init -y
2412
npm install laravel-mix --save-dev
25-
cp node_modules/laravel-mix/setup/webpack.mix.js ./
13+
```
14+
15+
Next, create a Mix configuration file within the root of your new project.
16+
17+
```
18+
touch webpack.mix.js
2619
```
2720

2821
You should now have the following directory structure:
@@ -33,33 +26,35 @@ You should now have the following directory structure:
3326

3427
`webpack.mix.js` is your configuration layer on top of webpack. Most of your time will be spent here.
3528

36-
Head over to your webpack.mix.js file:
29+
Head over there now, and add the following.
3730

3831
```js
32+
// webpack.mix.js
33+
3934
let mix = require('laravel-mix');
4035

41-
mix.js('src/app.js', 'dist')
42-
.sass('src/app.scss', 'dist')
43-
.setPublicPath('dist');
36+
mix.js('src/app.js', 'dist').setPublicPath('dist');
4437
```
4538

46-
Take note of the source paths. You're free to amend the paths to match your preferred structure, but if you're happy with our defaults simply run `mkdir src && touch src/app.{js,scss}` to create the files/directories. You're all set now. Compile everything down by running `node_modules/.bin/webpack` from the command line. You should now see:
39+
At its core, Mix is an opinionated, fluent API on top of webpack. In the example above, we've instructed Mix to compile `src/app.js` and save it to the `dist/` directory. If you're working along, create `src/app.js` now, and populate it with a simple alert:
4740

48-
- `dist/app.css`
49-
- `dist/app.js`
50-
- `dist/mix-manifest.json` (Your asset dump file, which we'll discuss later.)
41+
```js
42+
// src/app.js
43+
alert('hello world');
44+
```
5145

52-
Nice job! Now get to work on that project.
46+
Of course this is only a placeholder. We're now ready to compile. Mix provides a command-line program called `mix` which triggers the necessary webpack build. Give it a run now.
5347

54-
#### NPM Scripts
48+
```
49+
npx mix
50+
```
5551

56-
As a tip, consider adding the following NPM scripts to your `package.json` file, to speed up your workflow. Laravel installs will already include this.
52+
Congrats! You've created your first bundle. Create an HTML file, load your script, and you'll see an alert when the page loads.
5753

58-
```js
59-
"scripts": {
60-
"dev": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
61-
"watch": "NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
62-
"hot": "NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
63-
"production": "NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
64-
}
65-
```
54+
### Laravel Projects
55+
56+
Laravel ships with everything you need to get started. Simply:
57+
58+
- Install Laravel (`laravel new app`)
59+
- Run `npm install`
60+
- Visit your `webpack.mix.js file`, and get started!

docs/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
## Overview
44

5-
- [Basic Example](basic-example.md)
65
- [Installation](installation.md)
7-
- [Laravel Workflow](workflow.md)
6+
- [Basic Laravel Workflow](workflow.md)
87
- [FAQ](faq.md)
9-
- [Troubleshooting](troubleshooting.md)
108

119
## API
1210

docs/troubleshooting.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)