|
| 1 | +# The Mix API |
| 2 | + |
| 3 | +Below, you'll find the full Mix API. Out of the box, Mix supports a wide array of frameworks and preprocessors. |
| 4 | + |
| 5 | +The methods below assume that you've imported `mix` at the top of your `webpack.mix.js` file, like so: |
| 6 | + |
| 7 | +```js |
| 8 | +let mix = require('laravel-mix'); |
| 9 | +``` |
| 10 | + |
| 11 | +### `.js(src, output)` |
| 12 | + |
| 13 | +Bundle your JavaScript assets. |
| 14 | + |
| 15 | +```js |
| 16 | +mix.js('src/file.js', 'dist/file.js'); |
| 17 | +``` |
| 18 | + |
| 19 | +### `.ts(src, dist)` |
| 20 | + |
| 21 | +Bundle your TypeScript assets. |
| 22 | + |
| 23 | +```js |
| 24 | +mix.ts('src/file.ts', 'dist/file.js'); |
| 25 | +``` |
| 26 | + |
| 27 | +### `.vue(options?)` |
| 28 | + |
| 29 | +Add support for Vue single file components. |
| 30 | + |
| 31 | +```js |
| 32 | +mix.js('src/file.js', 'dist/file.js').vue(); |
| 33 | +``` |
| 34 | + |
| 35 | +Vue 2 and 3 differ slightly in how they should be bundled. Mix will do its best to check which |
| 36 | +version you currently have installed; however, if you wish, you can be explict. |
| 37 | + |
| 38 | +```js |
| 39 | +mix.js('src/file.js', 'dist/file.js').vue({ version: 2 }); |
| 40 | +``` |
| 41 | + |
| 42 | +### `.react()` |
| 43 | + |
| 44 | +Add support for React compilation. |
| 45 | + |
| 46 | +```js |
| 47 | +mix.js('src/file.js', 'dist/file.js').react(); |
| 48 | +``` |
| 49 | + |
| 50 | +### `.preact()` |
| 51 | + |
| 52 | +Add support for Preact compilation. |
| 53 | + |
| 54 | +```js |
| 55 | +mix.js('src/file.js', 'dist/file.js').preact(); |
| 56 | +``` |
| 57 | + |
| 58 | +### `.coffee(src, output)` |
| 59 | + |
| 60 | +Preprocess CoffeeScript files. |
| 61 | + |
| 62 | +```js |
| 63 | +mix.coffee('src/file.coffee', 'dist/file.js'); |
| 64 | +``` |
| 65 | + |
| 66 | +### `.postCss(src, output, plugins[]?)` |
| 67 | + |
| 68 | +Compile PostCss files. |
| 69 | + |
| 70 | +```js |
| 71 | +mix.postCss('src/file.css', 'dist/file.css', [ |
| 72 | + require('precss')() // your PostCss plugins |
| 73 | +]); |
| 74 | +``` |
| 75 | + |
| 76 | +### `.sass(src, output, sassPluginOptions?)` |
| 77 | + |
| 78 | +Compile Sass files. |
| 79 | + |
| 80 | +```js |
| 81 | +mix.sass('src/file.scss', 'dist/file.css'); |
| 82 | +``` |
| 83 | + |
| 84 | +### `.less(src, output)` |
| 85 | + |
| 86 | +Compile Less files. |
| 87 | + |
| 88 | +```js |
| 89 | +mix.less('src/file.less', 'dist/file.css'); |
| 90 | +``` |
| 91 | + |
| 92 | +### `.stylus(src, output)` |
| 93 | + |
| 94 | +Compile Stylus files. |
| 95 | + |
| 96 | +```js |
| 97 | +mix.stylus('src/file.styl', 'dist/file.css'); |
| 98 | +``` |
| 99 | + |
| 100 | +### `.extract(vendors?)` |
| 101 | + |
| 102 | +Use webpack code-splitting to extract any or all vendor dependencies into their own files. |
| 103 | + |
| 104 | +```js |
| 105 | +mix.js('src/file.js', 'dist/file.js').extract(['vue']); |
| 106 | +``` |
| 107 | + |
| 108 | +When no dependency is provided, Mix will bundle all imported dependencies from the `node_modules/` directory to a `vendor.js` file. |
| 109 | + |
| 110 | +```js |
| 111 | +mix.js('src/file.js', 'dist/file.js').extract(); |
| 112 | +``` |
| 113 | + |
| 114 | +### `.version(files[]?)` |
| 115 | + |
| 116 | +Version all compiled assets by appending a unique hash to every file within `mix-manifest.json`. This is useful for cache-busting purposes. |
| 117 | + |
| 118 | +```js |
| 119 | +mix.js('src/file.js', 'dist/file.js').version(); |
| 120 | +``` |
| 121 | + |
| 122 | +If using Laravel, refer to its global `mix()` helper function for dynamically accessing this hashed file path. |
| 123 | + |
| 124 | +```html |
| 125 | +<script src="{{ mix('js/app.js') }}"></script> |
| 126 | +``` |
| 127 | + |
| 128 | +### `.browserSync(domain)` |
| 129 | + |
| 130 | +Monitor files for changes and update the browser without requiring a manual page refresh. |
| 131 | + |
| 132 | +```js |
| 133 | +mix.js('...').browserSync('your-domain.test'); |
| 134 | +``` |
0 commit comments