Created
July 2, 2015 20:52
-
-
Save sulram/0338d0a5109aa6e8d6be to your computer and use it in GitHub Desktop.
EXPOSE WEBPACK + VUE MODULE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EXPOSE WEBPACK + VUE MODULE | |
// http://webpack.github.io/docs/library-and-externals.html | |
// http://paulsalaets.com/posts/expose-node-module-as-global-variable/ | |
// webpack.config.js | |
module.exports = { | |
entry: "./src/main.js", | |
output: { | |
path: "./build", | |
publicPath: "/build/", | |
filename: "build.js", | |
libraryTarget: "var", // export itself to a global var | |
library: "app" // name of the global var: "Foo" | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.styl$/, loader: "style!css!stylus" }, | |
{ test: /\.html$/, loader: "html" } | |
] | |
} | |
} | |
// module (main.js) | |
require('./main.styl') | |
var Vue = require('vue') | |
var app = new Vue({ | |
//el: '#app', | |
data: { | |
view: 'a' | |
}, | |
components: { | |
// define the main pages as async components. | |
a: function (resolve) { | |
require(['./views/a'], resolve) | |
}, | |
b: function (resolve) { | |
require(['./views/b'], resolve) | |
} | |
} | |
}) | |
function route () { | |
app.view = window.location.hash.slice(1) || 'a' | |
} | |
window.addEventListener('hashchange', route) | |
window.addEventListener('load', route) | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment