Skip to content

Commit ad003b5

Browse files
committed
initial demo spa app
0 parents  commit ad003b5

36 files changed

+1336
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": ["es2015", "stage-2"],
3+
"plugins": ["transform-runtime"],
4+
"comments": false
5+
}

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
root: true,
3+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
4+
extends: 'standard',
5+
// required to lint *.vue files
6+
plugins: [
7+
'html'
8+
],
9+
// add your custom rules here
10+
'rules': {
11+
// allow paren-less arrow functions
12+
'arrow-parens': 0,
13+
// allow debugger during development
14+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
15+
}
16+
}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
node_modules/
3+
dist/
4+
npm-debug.log

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# webpack-spa
2+
3+
> A Vue.js project
4+
5+
## Build Setup
6+
7+
``` bash
8+
# install dependencies
9+
npm install
10+
11+
# serve with hot reload at localhost:8080
12+
npm run dev
13+
14+
# build for production with minification
15+
npm run build
16+
17+
# run unit tests
18+
npm test
19+
```
20+
21+
For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).

build/css-loaders.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var ExtractTextPlugin = require('extract-text-webpack-plugin')
2+
3+
module.exports = function (options) {
4+
// generate loader string to be used with extract text plugin
5+
function generateLoaders (loaders) {
6+
var sourceLoader = loaders.map(function (loader) {
7+
var extraParamChar
8+
if (/\?/.test(loader)) {
9+
loader = loader.replace(/\?/, '-loader?')
10+
extraParamChar = '&'
11+
} else {
12+
loader = loader + '-loader'
13+
extraParamChar = '?'
14+
}
15+
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
16+
}).join('!')
17+
18+
if (options.extract) {
19+
return ExtractTextPlugin.extract('vue-style-loader', sourceLoader)
20+
} else {
21+
return ['vue-style-loader', sourceLoader].join('!')
22+
}
23+
}
24+
25+
// http://vuejs.github.io/vue-loader/configurations/extract-css.html
26+
return [
27+
{
28+
key: 'css',
29+
value: generateLoaders(['css'])
30+
},
31+
{
32+
key: 'less',
33+
value: generateLoaders(['css', 'less'])
34+
},
35+
{
36+
key: 'sass',
37+
value: generateLoaders(['css', 'sass?indentedSyntax'])
38+
},
39+
{
40+
key: 'scss',
41+
value: generateLoaders(['css', 'sass'])
42+
},
43+
{
44+
key: 'stylus',
45+
value: generateLoaders(['css', 'stylus'])
46+
},
47+
{
48+
key: 'styl',
49+
value: generateLoaders(['css', 'stylus'])
50+
}
51+
]
52+
}

build/dev-client.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
2+
3+
hotClient.subscribe(function (event) {
4+
if (event.action === 'reload') {
5+
window.location.reload()
6+
}
7+
})

build/dev-server.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var express = require('express')
2+
var webpack = require('webpack')
3+
var config = require('./webpack.dev.conf')
4+
5+
var app = express()
6+
var compiler = webpack(config)
7+
8+
var devMiddleware = require('webpack-dev-middleware')(compiler, {
9+
publicPath: config.output.publicPath,
10+
stats: {
11+
colors: true,
12+
chunks: false
13+
}
14+
})
15+
16+
var hotMiddleware = require('webpack-hot-middleware')(compiler)
17+
// force page reload when html-webpack-plugin template changes
18+
compiler.plugin('compilation', function (compilation) {
19+
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
20+
hotMiddleware.publish({ action: 'reload' })
21+
cb()
22+
})
23+
})
24+
25+
// handle fallback for HTML5 history API
26+
app.use(require('connect-history-api-fallback')())
27+
// serve webpack bundle output
28+
app.use(devMiddleware)
29+
// enable hot-reload and state-preserving
30+
// compilation error display
31+
app.use(hotMiddleware)
32+
// serve pure static assets
33+
app.use('/static', express.static('./static'))
34+
35+
app.listen(8080, function (err) {
36+
if (err) {
37+
console.log(err)
38+
return
39+
}
40+
console.log('Listening at http://localhost:8080')
41+
})

build/karma.conf.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var webpackConf = require('./webpack.base.conf')
2+
delete webpackConf.entry
3+
webpackConf.devtool = '#inline-source-map'
4+
5+
module.exports = function (config) {
6+
config.set({
7+
browsers: ['PhantomJS'],
8+
frameworks: ['jasmine'],
9+
reporters: ['spec'],
10+
files: ['../test/unit/index.js'],
11+
preprocessors: {
12+
'../test/unit/index.js': ['webpack', 'sourcemap']
13+
},
14+
webpack: webpackConf,
15+
webpackMiddleware: {
16+
noInfo: true
17+
}
18+
})
19+
}

build/webpack.base.conf.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var path = require('path')
2+
3+
module.exports = {
4+
entry: {
5+
app: './src/main.js'
6+
},
7+
output: {
8+
path: path.resolve(__dirname, '../dist/static'),
9+
publicPath: '/static/',
10+
filename: '[name].js'
11+
},
12+
resolve: {
13+
extensions: ['', '.js', '.vue'],
14+
fallback: [path.join(__dirname, '../node_modules')],
15+
alias: {
16+
'src': path.resolve(__dirname, '../src')
17+
}
18+
},
19+
resolveLoader: {
20+
fallback: [path.join(__dirname, '../node_modules')]
21+
},
22+
module: {
23+
preLoaders: [
24+
{
25+
test: /\.vue$/,
26+
loader: 'eslint',
27+
exclude: /node_modules/
28+
},
29+
{
30+
test: /\.js$/,
31+
loader: 'eslint',
32+
exclude: /node_modules/
33+
}
34+
],
35+
loaders: [
36+
{
37+
test: /\.vue$/,
38+
loader: 'vue'
39+
},
40+
{
41+
test: /\.js$/,
42+
loader: 'babel',
43+
exclude: /node_modules/
44+
},
45+
{
46+
test: /\.json$/,
47+
loader: 'json'
48+
},
49+
{
50+
test: /\.html$/,
51+
loader: 'vue-html'
52+
},
53+
{
54+
test: /\.(png|jpg|gif|svg)$/,
55+
loader: 'url',
56+
query: {
57+
limit: 10000,
58+
name: '[name].[ext]?[hash:7]'
59+
}
60+
}
61+
]
62+
},
63+
eslint: {
64+
formatter: require('eslint-friendly-formatter')
65+
}
66+
}

build/webpack.dev.conf.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var webpack = require('webpack')
2+
var config = require('./webpack.base.conf')
3+
var cssLoaders = require('./css-loaders')
4+
var HtmlWebpackPlugin = require('html-webpack-plugin')
5+
6+
// eval-source-map is faster for development
7+
config.devtool = '#eval-source-map'
8+
9+
config.vue = config.vue || {}
10+
config.vue.loaders = config.vue.loaders || {}
11+
cssLoaders({
12+
sourceMap: false,
13+
extract: false
14+
}).forEach(function (loader) {
15+
config.vue.loaders[loader.key] = loader.value
16+
})
17+
18+
// add hot-reload related code to entry chunks
19+
var polyfill = 'eventsource-polyfill'
20+
var devClient = './build/dev-client'
21+
Object.keys(config.entry).forEach(function (name, i) {
22+
var extras = i === 0 ? [polyfill, devClient] : [devClient]
23+
config.entry[name] = extras.concat(config.entry[name])
24+
})
25+
26+
// necessary for the html plugin to work properly
27+
// when serving the html from in-memory
28+
config.output.publicPath = '/'
29+
30+
config.plugins = (config.plugins || []).concat([
31+
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
32+
new webpack.optimize.OccurenceOrderPlugin(),
33+
new webpack.HotModuleReplacementPlugin(),
34+
new webpack.NoErrorsPlugin(),
35+
// https://github.com/ampedandwired/html-webpack-plugin
36+
new HtmlWebpackPlugin({
37+
filename: 'index.html',
38+
template: 'index.html',
39+
inject: true
40+
})
41+
])
42+
43+
module.exports = config

build/webpack.prod.conf.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var webpack = require('webpack')
2+
var config = require('./webpack.base.conf')
3+
var cssLoaders = require('./css-loaders')
4+
var ExtractTextPlugin = require('extract-text-webpack-plugin')
5+
var HtmlWebpackPlugin = require('html-webpack-plugin')
6+
7+
// naming output files with hashes for better caching.
8+
// dist/index.html will be auto-generated with correct URLs.
9+
config.output.filename = '[name].[chunkhash].js'
10+
config.output.chunkFilename = '[id].[chunkhash].js'
11+
12+
// whether to generate source map for production files.
13+
// disabling this can speed up the build.
14+
var SOURCE_MAP = true
15+
16+
config.devtool = SOURCE_MAP ? '#source-map' : false
17+
18+
config.vue = config.vue || {}
19+
config.vue.loaders = config.vue.loaders || {}
20+
cssLoaders({
21+
sourceMap: SOURCE_MAP,
22+
extract: true
23+
}).forEach(function (loader) {
24+
config.vue.loaders[loader.key] = loader.value
25+
})
26+
27+
config.plugins = (config.plugins || []).concat([
28+
// http://vuejs.github.io/vue-loader/workflow/production.html
29+
new webpack.DefinePlugin({
30+
'process.env': {
31+
NODE_ENV: '"production"'
32+
}
33+
}),
34+
new webpack.optimize.UglifyJsPlugin({
35+
compress: {
36+
warnings: false
37+
}
38+
}),
39+
new webpack.optimize.OccurenceOrderPlugin(),
40+
// extract css into its own file
41+
new ExtractTextPlugin('[name].[contenthash].css'),
42+
// generate dist index.html with correct asset hash for caching.
43+
// you can customize output by editing /index.html
44+
// see https://github.com/ampedandwired/html-webpack-plugin
45+
new HtmlWebpackPlugin({
46+
filename: '../index.html',
47+
template: 'index.html',
48+
inject: true,
49+
minify: {
50+
removeComments: true,
51+
collapseWhitespace: true,
52+
removeAttributeQuotes: true
53+
// more options:
54+
// https://github.com/kangax/html-minifier#options-quick-reference
55+
}
56+
})
57+
])
58+
59+
module.exports = config

index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Webpack Single Page App</title>
6+
<link rel="stylesheet" href="/static/normalize.css" />
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<!-- built files will be auto injected -->
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)