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.

Selecting a build<br />

A good build for <strong>Vue</strong>bnb is vue.runtime.esm.<strong>js</strong> since we're using Webpack <strong>and</strong> we<br />

don't need the template compiler. We could also use vue.runtime.common.<strong>js</strong>, but that<br />

wouldn't be consistent with our use of ES modules elsewhere in the project. In<br />

practice, though, there is no difference as Webpack will process them in the<br />

same way.<br />

Remember that we include <strong>Vue</strong> at the top of our entry file with the statement<br />

import <strong>Vue</strong> from 'vue'. The last 'vue' is an alias to the <strong>Vue</strong> build that Webpack<br />

resolves when it runs. Currently, this alias is defined within the default Mix<br />

configuration <strong>and</strong> is set to the build vue.common.<strong>js</strong>. We can override that<br />

configuration by adding the following to the bottom of our webpack.mix.<strong>js</strong> file.<br />

webpack.mix.<strong>js</strong>: ...<br />

mix.webpackConfig({ resolve: { alias: { 'vue$': 'vue/dist/vue.runtime.esm.<strong>js</strong>' } }<br />

});<br />

After a new build, we should expect to see a smaller bundle size due to the<br />

template compiler being removed. In the following screenshot, I've shown the<br />

bundle before <strong>and</strong> after I ran a dev build in a separate Terminal tab:<br />

Figure 6.17. The difference between bundle sizes after applying the runtime-only build Keep in mind that<br />

without the template compiler we can no longer provide string templates for our components. Doing so will<br />

cause an error at runtime. That shouldn't be a problem though since we've got the far more powerful option<br />

of SFCs.

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

Saved successfully!

Ooh no, something went wrong!