25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Vue</strong>.<strong>js</strong> dependency<br />

Let's now import <strong>Vue</strong>.<strong>js</strong> as a dependency of our entry file.<br />

resources/assets/<strong>js</strong>/app.<strong>js</strong>: import <strong>Vue</strong> from 'vue'; import sample from './data'; var<br />

app = new <strong>Vue</strong>({ ... });<br />

Running the build again, we'll now see <strong>Vue</strong>.<strong>js</strong> in the list of modules in the<br />

Terminal output, plus some dependencies that it has introduced:<br />

Figure 5.10. Webpack Terminal output showing <strong>Vue</strong>.<strong>js</strong> You may be wondering how import <strong>Vue</strong> from<br />

'vue' resolves, as it doesn't seem to be a proper file reference. Webpack will, by default, check the<br />

node_modules folder in the project for any dependencies, saving you from having to put import <strong>Vue</strong> from<br />

'node_modules/vue';.<br />

But how, then, does it know the entry file of this package? Looking at the<br />

Webpack Terminal output in the preceding screenshot, you can see that it has<br />

included node_modules/vue/dist/vue.common.<strong>js</strong>. It knows to use this file because, when<br />

Webpack is adding node modules as dependencies, it checks their package.<strong>js</strong>on file<br />

<strong>and</strong> looks for the main property, which in the case of <strong>Vue</strong> is.<br />

node_modules/vue/package.<strong>js</strong>on: { ... "main": "dist/vue.runtime.common.<strong>js</strong>", ... }<br />

However, <strong>Laravel</strong> Mix overrides this to force a different <strong>Vue</strong> build.<br />

node_modules/laravel-mix/setup/webpack.config.<strong>js</strong>: alias: { 'vue$':<br />

'vue/dist/vue.common.<strong>js</strong>' }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!