Add aliases and update examples

This commit is contained in:
Sébastien Chopin 2016-11-16 17:55:15 +01:00
parent a8bdf85549
commit b1546682ef
14 changed files with 31 additions and 21 deletions

View File

@ -10,7 +10,7 @@ module.exports = {
loaders: [ loaders: [
{ {
test: /\.(png|jpg|gif|svg)$/, test: /\.(png|jpg|gif|svg)$/,
loader: 'url', loader: 'url-loader',
options: { options: {
limit: 100000, // 100KO limit: 100000, // 100KO
name: 'img/[name].[ext]?[hash]' name: 'img/[name].[ext]?[hash]'

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="container"> <div class="container">
<p><img src="../assets/nuxt.png" /></p> <p><img src="~assets/nuxt.png" /></p>
<p>This image is included as data:image/png;base64...</p> <p>This image is included as data:image/png;base64...</p>
<p>In the source code, the files generated are based on the build.filenames data.</p> <p>In the source code, the files generated are based on the build.filenames data.</p>
<p>If you look at the <a href="/_nuxt/vendor.js">vendor.js</a>, lodash has been included (cmd/ctrl + F "lodash").</p> <p>If you look at the <a href="/_nuxt/vendor.js">vendor.js</a>, lodash has been included (cmd/ctrl + F "lodash").</p>

View File

@ -1,3 +1,3 @@
module.exports = { module.exports = {
loading: 'components/loading' loading: '~components/loading'
} }

View File

@ -1,7 +1,7 @@
module.exports = { module.exports = {
router: { router: {
routes: [ routes: [
{ name: 'user', path: '/users/:id', component: 'pages/_user' } { name: 'user', path: '/users/:id', component: '~pages/_user' }
] ]
} }
} }

View File

@ -1,9 +1,9 @@
const { resolve } = require('path') const { join } = require('path')
module.exports = { module.exports = {
css: [ css: [
'hover.css/css/hover-min.css', 'hover.css/css/hover-min.css',
{ src: 'bulma', lang: 'sass' }, { src: 'bulma', lang: 'sass' },
resolve(__dirname, 'css/main.css') join(__dirname, 'css/main.css')
] ]
} }

View File

@ -7,7 +7,7 @@
</template> </template>
<script> <script>
import TwitterHead from '../components/twitter-head.vue' import TwitterHead from '~components/twitter-head.vue'
export default { export default {
head: { head: {

View File

@ -22,8 +22,8 @@
</template> </template>
<script> <script>
import Post from '../components/post.vue' import Post from '~components/post.vue'
import vP from '../components/paragraph.vue' import vP from '~components/paragraph.vue'
const vHr = { render: (h) => h('hr', { class: 'hr' }) } const vHr = { render: (h) => h('hr', { class: 'hr' }) }
export default { export default {

View File

@ -40,10 +40,12 @@ module.exports = {
build: { build: {
vendor: ['vue-notifications'] vendor: ['vue-notifications']
}, },
plugins: [ join(__dirname, './plugins/vue-notifications') ] plugins: [ '~plugins/vue-notifications') ]
} }
``` ```
I use `~plugins` here because nuxt.js create an alias for the `plugins/` folder, it's equivalent to: `join(__dirname, './plugins/vue-notifications.js')`
I added `vue-notifications` in the `vendor` key to make sure that it won't be included in any other build if I call `require('vue-notifications')` in a component. I added `vue-notifications` in the `vendor` key to make sure that it won't be included in any other build if I call `require('vue-notifications')` in a component.
### Only in browser build ### Only in browser build

View File

@ -1,8 +1,8 @@
const { join } = require('path')
module.exports = { module.exports = {
build: { build: {
vendor: ['axios', 'mini-toastr', 'vue-notifications'] vendor: ['axios', 'mini-toastr', 'vue-notifications']
}, },
plugins: [ join(__dirname, './plugins/vue-notifications.js') ] plugins: [
'~plugins/vue-notifications.js'
]
} }

View File

@ -1,7 +1,7 @@
'use strict' 'use strict'
require('es6-promise').polyfill()
require('es6-object-assign').polyfill() require('es6-object-assign').polyfill()
import 'es6-promise/auto'
import Vue from 'vue' import Vue from 'vue'
import { app, router<%= (store ? ', store' : '') %> } from './index' import { app, router<%= (store ? ', store' : '') %> } from './index'
import { getMatchedComponents, flatMapComponents, getContext, getLocation } from './utils' import { getMatchedComponents, flatMapComponents, getContext, getLocation } from './utils'

View File

@ -5,7 +5,7 @@
import Vue from 'vue' import Vue from 'vue'
import Meta from 'vue-meta/lib/vue-meta.js' // require the ES2015 lib import Meta from 'vue-meta/lib/vue-meta.js' // require the ES2015 lib
import router from './router' import router from './router'
<% if (store && storePath) { %>import store from '<%= storePath %>'<% } %> <% if (store) { %>import store from '~store'<% } %>
Vue.use(Meta, { Vue.use(Meta, {
keyName: 'head', // the component option name that vue-meta looks for meta info on. keyName: 'head', // the component option name that vue-meta looks for meta info on.

View File

@ -100,7 +100,10 @@ module.exports = function * () {
if (route.component.slice(-4) !== '.vue') { if (route.component.slice(-4) !== '.vue') {
route.component = route.component + '.vue' route.component = route.component + '.vue'
} }
route.component = r(this.dir, route.component) // If not using an alias
if (route.component.indexOf('~') === -1) {
route.component = r(this.dir, route.component)
}
}) })
// Generate routes and interpret the template files // Generate routes and interpret the template files
yield generateRoutesAndFiles.call(this) yield generateRoutesAndFiles.call(this)
@ -175,9 +178,6 @@ function * generateRoutesAndFiles () {
route._name = '_' + hash(route._component) route._name = '_' + hash(route._component)
route.component = route._name route.component = route._name
}) })
if (this.options.store) {
templateVars.storePath = r(this.dir, 'store')
}
if (this.dev && files.includes('pages/_error-debug.vue')) { if (this.dev && files.includes('pages/_error-debug.vue')) {
templateVars.components.ErrorPage = r(this.dir, 'pages/_error-debug.vue') templateVars.components.ErrorPage = r(this.dir, 'pages/_error-debug.vue')
} }

View File

@ -23,8 +23,16 @@ module.exports = function () {
publicPath: urlJoin(this.options.router.base, '/_nuxt/') publicPath: urlJoin(this.options.router.base, '/_nuxt/')
}, },
resolve: { resolve: {
// Disable for now
alias: { alias: {
'static': join(this.dir, 'static') 'static': join(this.dir, 'static'), // use in template with <img src="~static/nuxt.png" />
'~static': join(this.dir, 'static'),
'assets': join(this.dir, 'assets'), // use in template with <img src="~static/nuxt.png" />
'~assets': join(this.dir, 'assets'),
'~plugins': join(this.dir, 'plugins'),
'~store': join(this.dir, 'store'),
'~pages': join(this.dir, 'pages'),
'~components': join(this.dir, 'components')
}, },
modules: [ modules: [
nodeModulesDir, nodeModulesDir,

View File

@ -1,6 +1,6 @@
{ {
"name": "nuxt", "name": "nuxt",
"version": "0.4.0", "version": "0.4.1",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)", "description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",