From 716f6946a7b56407948979a70ab2c61b431a903e Mon Sep 17 00:00:00 2001 From: AndroidDrew Date: Sun, 19 Nov 2017 13:05:49 -0500 Subject: [PATCH] Initial commit --- .editorconfig | 9 +++++++++ .eslintrc.js | 11 ++++++++++ .gitignore | 3 +++ LICENSE | 8 ++++++++ README.md | 24 ++++++++++++++++++++++ build/dev-server.js | 25 +++++++++++++++++++++++ build/webpack.base.config.js | 37 ++++++++++++++++++++++++++++++++++ build/webpack.client.config.js | 8 ++++++++ dist/.gitignore | 0 index.html | 14 +++++++++++++ package.json | 29 ++++++++++++++++++++++++++ server.js | 26 ++++++++++++++++++++++++ src/app.js | 10 +++++++++ src/client-entry.js | 8 ++++++++ 14 files changed, 212 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 build/dev-server.js create mode 100644 build/webpack.base.config.js create mode 100644 build/webpack.client.config.js create mode 100644 dist/.gitignore create mode 100644 index.html create mode 100644 package.json create mode 100644 server.js create mode 100644 src/app.js create mode 100644 src/client-entry.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9d08a1a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..7415487 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,11 @@ +module.exports = { + root: true, //sets this file as the parent scope for the rules + parserOptions:{ + sourceType: 'module' + }, + extends: 'standard', + //required to lint *.vue files + plugins: [ + 'html' + ] +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..764a5aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +dist/*.js +dist/*.css diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9d6ba0f --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ +MIT License +Copyright (c) 2017 Drew Bednar + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..549ce9a --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Vuejs SPA + +A Vuejs SPA application + +## Installation + +`npm install` + +## Dev server + +`npm start` + +## Features + +- Webpack build process +- ESLinting +- Dev live reloading +- Routing +- State management + + +## License + +MIT diff --git a/build/dev-server.js b/build/dev-server.js new file mode 100644 index 0000000..1a21c9f --- /dev/null +++ b/build/dev-server.js @@ -0,0 +1,25 @@ +const webpack = require('webpack') +const clientConfig = require('./webpack.client.config') + +module.exports = function setupDevServer(app) { + //hot middleware + clientConfig.entry.app = [ + 'webpack-hot-middleware/client', + clientConfig.entry.app + ] + + clientConfig.plugins.push( + new webpack.HotModuleReplacementPlugin(), + new webpack.NoEmitOnErrorsPlugin() + ) + + const clientCompiler = webpack(clientConfig) + app.use( + require('webpack-dev-middleware')(clientCompiler, { + stats:{ + colors: true + } + }) + ) + app.use(require('webpack-hot-middleware')(clientCompiler)) +} diff --git a/build/webpack.base.config.js b/build/webpack.base.config.js new file mode 100644 index 0000000..0218f9d --- /dev/null +++ b/build/webpack.base.config.js @@ -0,0 +1,37 @@ + const path = require('path') + + const config = { + entry: { + app: path.resolve(__dirname, '../src/client-entry.js') + }, + + //Path for output files + output:{ + path: path.resolve(__dirname, '../dist'), //where we eventually deploy. Notice it's relative to this file location + publicPath: '/', //dist folder availble through our site through the root path + filename: 'assets/js/[name].js' // + }, + + //We do not want to use this in production because it + //instead we whatnt o make sure that all components are defined in *.vuejs + //files, because they are pre-compiled + resolve: { // What the hell does resolve do? + alias:{ + vue: 'vue/dist/vue.js' + } + }, + + module: { + rules: [ + { + enforce: 'pre', //check source files before they are loader by other loaders + test: /(\.js$)/, + loader: 'eslint-loader', + exclude: /node_modules/ + } + ] + } + + } + + module.exports = config diff --git a/build/webpack.client.config.js b/build/webpack.client.config.js new file mode 100644 index 0000000..9aa8966 --- /dev/null +++ b/build/webpack.client.config.js @@ -0,0 +1,8 @@ +const base = require('./webpack.base.config') + +//extends the base config object and include the new property plugins +const config = Object.assign({}, base, { + plugins: base.plugins || [] +}) + +module.exports = config diff --git a/dist/.gitignore b/dist/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..f0b30a8 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ + + + + + Vuejs SPA + + + +
+ {{ message }} +
+ + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..cf719dc --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "vuejs_spa", + "version": "0.1.0", + "description": "A Vuejs SPA application", + "scripts": { + "start": "node server", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Drew Bednar", + "license": "MIT", + "dependencies": { + "express": "^4.16.2", + "vue": "^2.5.5" + }, + "devDependencies": { + "eslint": "^4.5.0", + "eslint-config-standard": "^10.2.1", + "eslint-loader": "^1.9.0", + "eslint-plugin-html": "^3.2.0", + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-node": "^5.1.1", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1", + "webpack": "^3.8.1", + "webpack-dev-middleware": "^1.12.0", + "webpack-hot-middleware": "^2.20.0" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..3a9cb4f --- /dev/null +++ b/server.js @@ -0,0 +1,26 @@ +const express = require('express'); +const app = express(); +const fs = require('fs'); +const path = require('path'); + +const indexHTML = (() => { + //path.resolve helps us locate the file relative to the server.js file + return fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf-8"); +})(); //iffy + +//used to retrun all static modules from the dist folder +app.use("/dist", express.static(path.resolve(__dirname, "./dist"))); + +//this extends the server with two new modules in the setupdeverser method +require("./build/dev-server")(app); + +app.get('*', (req, res) => { + res.write(indexHTML); + res.end(); +}); + + +const port = process.env.PORT || 3000; +app.listen(port, () => { + console.log(`Server started at http://localhost:${port}`); +}); diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..07bdae5 --- /dev/null +++ b/src/app.js @@ -0,0 +1,10 @@ +import Vue from 'vue' + +const app = new Vue({ + data: { + message: 'Hello Vue' + }, + template: '
{{ message }}
' +}) + +export { app } diff --git a/src/client-entry.js b/src/client-entry.js new file mode 100644 index 0000000..16f7ac2 --- /dev/null +++ b/src/client-entry.js @@ -0,0 +1,8 @@ +import { app } from './app' + +// We can use the $mount when we didn't specify the el property name +app.$mount('#app') + +if (module.hot) { + module.hot.accept() +}