Skip to content

Commit cafc7f8

Browse files
committed
update
1 parent 8699a8d commit cafc7f8

File tree

17 files changed

+338
-10052
lines changed

17 files changed

+338
-10052
lines changed

build/dev-client.js

Lines changed: 7 additions & 0 deletions
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.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var path = require('path')
2+
var express = require('express')
3+
var webpack = require('webpack')
4+
var config = require('../config')
5+
var utils = require('./utils')
6+
var chalk = require('chalk')
7+
var ora = require('ora')
8+
var webpackConfig = require('./webpack.dev.config')
9+
10+
var port = process.argv[2] || config.dev.port
11+
12+
var app = express()
13+
var compiler = webpack(webpackConfig)
14+
15+
var devMiddleware = require('webpack-dev-middleware')(compiler, {
16+
publicPath: webpackConfig.output.publicPath,
17+
noInfo: true,
18+
stats: {
19+
colors: true,
20+
chunks: false
21+
}
22+
})
23+
24+
var hotMiddleware = require('webpack-hot-middleware')(compiler,{
25+
log:log
26+
})
27+
28+
function log(){
29+
if(arguments[0].indexOf("building")>-1){
30+
console.log(chalk.gray(" - "))
31+
return
32+
}
33+
console.log(chalk.gray(" > "+arguments[0]))
34+
}
35+
compiler.plugin('compilation', function(compilation) {
36+
compilation.plugin('html-webpack-plugin-after-emit', function(data, cb) {
37+
hotMiddleware.publish({
38+
action: 'reload'
39+
})
40+
cb()
41+
})
42+
})
43+
44+
app.use(require('connect-history-api-fallback')())
45+
app.use(devMiddleware)
46+
app.use(hotMiddleware)
47+
48+
module.exports = app.listen(port, function(err) {
49+
if (err) {
50+
console.log(err)
51+
return
52+
}
53+
console.log(chalk.blue(' # Access URLs:'))
54+
console.log(chalk.gray(' ----------------------------------------'))
55+
console.log(' Local: ' + chalk.green('http://localhost:' + port))
56+
console.log(' External: ' + chalk.green('http://' + utils.ip + ':' + port))
57+
console.log(chalk.gray(' ----------------------------------------'))
58+
console.log('')
59+
})

build/utils.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var path = require('path')
2+
var config = require('../config')
3+
var ifaces = require("os").networkInterfaces()
4+
5+
exports.assetsPath = function(_path) {
6+
return path.posix.join(config.build.assetsSubDirectory, _path)
7+
}
8+
9+
10+
/**
11+
* 获取本机ip地址
12+
*/
13+
exports.ip = getIp()
14+
15+
16+
function getIp() {
17+
var ip = "127.0.0.1"
18+
19+
for (var dev in ifaces) {
20+
var alias = 0
21+
22+
ifaces[dev].forEach(function(details) {
23+
if (details.family == 'IPv4' && details.address !== '127.0.0.1') {
24+
//console.log(dev + (alias ? ':' + alias : ''), details.address)
25+
ip = details.address
26+
alias++
27+
}
28+
})
29+
}
30+
return ip
31+
}

build/webpack.base.config.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var path = require('path')
2+
var px2rem = require('postcss-px2rem')
3+
var config = require("../config.js")
4+
var utils = require('./utils')
5+
6+
module.exports = {
7+
entry: {
8+
app: './src/app.vue'
9+
},
10+
output: {
11+
path: config.build.assetsRoot,
12+
publicPath: config.build.assetsPublicPath,
13+
filename: '[name].js'
14+
},
15+
resolve: {
16+
extensions: ['', '.css','.js', '.vue'],
17+
fallback: [path.join(__dirname, '../node_modules')],
18+
alias: {
19+
'src': path.resolve(__dirname, '../src'),
20+
'components': path.resolve(__dirname, '../src/components'),
21+
'fonts': path.resolve(__dirname, '../src/fonts'),
22+
'css': path.resolve(__dirname, '../src/css'),
23+
'svgs': path.resolve(__dirname, '../src/svgs'),
24+
'images': path.resolve(__dirname, '../src/images'),
25+
'libs': path.resolve(__dirname, '../src/libs')
26+
}
27+
},
28+
resolveLoader: {
29+
fallback: [path.join(__dirname, '../node_modules')]
30+
},
31+
module: {
32+
loaders: [{
33+
test: /\.vue$/,
34+
loader: 'vue'
35+
}, {
36+
test: /\.js$/,
37+
loader: 'babel',
38+
include: path.resolve(__dirname, '../'),
39+
exclude: /node_modules/
40+
}, {
41+
test: /\.css$/,
42+
loader: 'style!css'
43+
},{
44+
test: /\.json$/,
45+
loader: 'json'
46+
}, {
47+
test: /\.html$/,
48+
loader: 'vue-html'
49+
}, {
50+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
51+
loader: 'url',
52+
query: {
53+
limit: 10000,
54+
name: utils.assetsPath('img/[name].[hash:7].[ext]')
55+
}
56+
}, {
57+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
58+
loader: 'url',
59+
query: {
60+
limit: 10000,
61+
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
62+
}
63+
}]
64+
},
65+
babel: {
66+
presets: ['es2015', 'stage-0'],
67+
plugins: ['transform-runtime']
68+
},
69+
vue: {
70+
postcss: [
71+
px2rem({
72+
remUnit: 75
73+
})
74+
]
75+
}
76+
}

build/webpack.dev.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var webpack = require('webpack')
2+
var merge = require('webpack-merge')
3+
var utils = require('./utils')
4+
var baseWebpackConfig = require('./webpack.base.config')
5+
var HtmlWebpackPlugin = require('html-webpack-plugin')
6+
7+
8+
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
9+
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
10+
})
11+
12+
module.exports = merge(baseWebpackConfig,{
13+
devtool: '#source-map',
14+
plugins: [
15+
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
16+
new webpack.optimize.OccurenceOrderPlugin(),
17+
new webpack.HotModuleReplacementPlugin(),
18+
new webpack.NoErrorsPlugin(),
19+
new HtmlWebpackPlugin({
20+
filename: 'index.html',
21+
template: 'index.html',
22+
inject: true
23+
}),
24+
new webpack.BannerPlugin("date: ",new Date().toLocaleString())
25+
]
26+
})

config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var path = require('path')
2+
3+
module.exports = {
4+
build: {
5+
index: path.resolve(__dirname, 'dist/index.html'),
6+
assetsRoot: path.resolve(__dirname, 'dist'),
7+
assetsSubDirectory: 'static',
8+
assetsPublicPath: '/',
9+
productionSourceMap: true
10+
},
11+
dev: {
12+
port: 8080
13+
}
14+
}

src/index.html renamed to index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<meta charset="utf-8">
66
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
7-
<title>Demo</title>
7+
<title>Demo vue</title>
88
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
99
<meta name="description" content="">
1010
<meta name="author" content="DIGIOCEAN (http://www.digiocean.cc/)">
@@ -16,7 +16,7 @@
1616
</head>
1717

1818
<body>
19-
19+
<h1>title</h1>
2020
</body>
2121

2222
</html>

npm-debug.log

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'dev' ]
3+
2 info using [email protected]
4+
3 info using [email protected]
5+
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
6+
5 info predev [email protected]
7+
8+
7 verbose unsafe-perm in lifecycle true
9+
8 info [email protected] Failed to exec dev script
10+
9 verbose stack Error: [email protected] dev: `node build/dev.js`
11+
9 verbose stack Exit status 1
12+
9 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:217:16)
13+
9 verbose stack at emitTwo (events.js:87:13)
14+
9 verbose stack at EventEmitter.emit (events.js:172:7)
15+
9 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
16+
9 verbose stack at emitTwo (events.js:87:13)
17+
9 verbose stack at ChildProcess.emit (events.js:172:7)
18+
9 verbose stack at maybeClose (internal/child_process.js:827:16)
19+
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
20+
10 verbose pkgid [email protected]
21+
11 verbose cwd /Users/hyingzi/DEV/digiocean/generator/generator-vue
22+
12 error Darwin 15.4.0
23+
13 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
24+
14 error node v4.4.3
25+
15 error npm v2.15.1
26+
16 error code ELIFECYCLE
27+
17 error [email protected] dev: `node build/dev.js`
28+
17 error Exit status 1
29+
18 error Failed at the [email protected] dev script 'node build/dev.js'.
30+
18 error This is most likely a problem with the generator-vue package,
31+
18 error not with npm itself.
32+
18 error Tell the author that this fails on your system:
33+
18 error node build/dev.js
34+
18 error You can get information on how to open an issue for this project with:
35+
18 error npm bugs generator-vue
36+
18 error Or if that isn't available, you can get their info via:
37+
18 error
38+
18 error npm owner ls generator-vue
39+
18 error There is likely additional logging output above.
40+
19 verbose exit [ 1, true ]

package.json

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,47 @@
22
"name": "generator-vue",
33
"version": "1.0.0",
44
"description": "digiocean generator",
5-
"main": "index.js",
5+
"author": "h.yingzi",
6+
"private": true,
7+
"license": "MIT",
68
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"start": "node build/dev.js",
10+
"test": ""
811
},
912
"keywords": [
1013
"digiocean",
1114
"generator",
1215
"vue"
1316
],
14-
"author": "h.yingzi",
15-
"license": "MIT"
17+
"dependencies": {
18+
"vue": "^1.0.21",
19+
"babel-runtime": "^6.0.0"
20+
},
21+
"devDependencies": {
22+
"babel-core": "^6.8.0",
23+
"babel-loader": "^6.0.0",
24+
"babel-plugin-transform-runtime": "^6.0.0",
25+
"babel-preset-es2015": "^6.0.0",
26+
"babel-preset-stage-0": "^6.0.0",
27+
"chalk": "^1.1.3",
28+
"connect-history-api-fallback": "^1.1.0",
29+
"css-loader": "^0.23.0",
30+
"file-loader": "^0.8.4",
31+
"html-webpack-plugin": "^2.8.1",
32+
"json-loader": "^0.5.4",
33+
"ora": "^0.2.0",
34+
"postcss-px2rem": "^0.2.0",
35+
"style-loader": "^0.13.1",
36+
"url-loader": "^0.5.7",
37+
"vue-hot-reload-api": "^1.2.0",
38+
"vue-html-loader": "^1.0.0",
39+
"vue-loader": "^8.3.0",
40+
"vue-router": "^0.7.13",
41+
"vue-style-loader": "^1.0.0",
42+
"vuex": "^0.6.3",
43+
"webpack": "^1.12.2",
44+
"webpack-dev-middleware": "^1.4.0",
45+
"webpack-hot-middleware": "^2.6.0",
46+
"webpack-merge": "^0.8.3"
47+
}
1648
}

src/.tags

Whitespace-only changes.

0 commit comments

Comments
 (0)