Skip to content

Commit f71f59b

Browse files
1、初始化项目
1 parent 37eb1b7 commit f71f59b

29 files changed

+828
-1
lines changed

.idea/encodings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vue2-template.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

100644100755
+24-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
#vue2-template
1+
# vue-template
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 e2e tests
18+
npm run e2e
19+
20+
# run all tests
21+
npm test
22+
```
23+
24+
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).

build/build.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// https://github.com/shelljs/shelljs
2+
require('./check-versions')()
3+
require('shelljs/global')
4+
env.NODE_ENV = 'production'
5+
6+
var path = require('path')
7+
var config = require('../config')
8+
var ora = require('ora')
9+
var webpack = require('webpack')
10+
var webpackConfig = require('./webpack.prod.conf')
11+
12+
console.log(
13+
' Tip:\n' +
14+
' Built files are meant to be served over an HTTP server.\n' +
15+
' Opening index.html over file:// won\'t work.\n'
16+
)
17+
18+
var spinner = ora('building for production...')
19+
spinner.start()
20+
21+
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
22+
rm('-rf', assetsPath)
23+
mkdir('-p', assetsPath)
24+
cp('-R', 'static/*', assetsPath)
25+
26+
webpack(webpackConfig, function (err, stats) {
27+
spinner.stop()
28+
if (err) throw err
29+
process.stdout.write(stats.toString({
30+
colors: true,
31+
modules: false,
32+
children: false,
33+
chunks: false,
34+
chunkModules: false
35+
}) + '\n')
36+
})

build/check-versions.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var semver = require('semver')
2+
var chalk = require('chalk')
3+
var packageConfig = require('../package.json')
4+
var exec = function (cmd) {
5+
return require('child_process')
6+
.execSync(cmd).toString().trim()
7+
}
8+
9+
var versionRequirements = [
10+
{
11+
name: 'node',
12+
currentVersion: semver.clean(process.version),
13+
versionRequirement: packageConfig.engines.node
14+
},
15+
{
16+
name: 'npm',
17+
currentVersion: exec('npm --version'),
18+
versionRequirement: packageConfig.engines.npm
19+
}
20+
]
21+
22+
module.exports = function () {
23+
var warnings = []
24+
for (var i = 0; i < versionRequirements.length; i++) {
25+
var mod = versionRequirements[i]
26+
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
27+
warnings.push(mod.name + ': ' +
28+
chalk.red(mod.currentVersion) + ' should be ' +
29+
chalk.green(mod.versionRequirement)
30+
)
31+
}
32+
}
33+
34+
if (warnings.length) {
35+
console.log('')
36+
console.log(chalk.yellow('To use this template, you must update following to modules:'))
37+
console.log()
38+
for (var i = 0; i < warnings.length; i++) {
39+
var warning = warnings[i]
40+
console.log(' ' + warning)
41+
}
42+
console.log()
43+
process.exit(1)
44+
}
45+
}

build/dev-client.js

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

build/dev-server.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require('./check-versions')()
2+
var config = require('../config')
3+
if (!process.env.NODE_ENV) process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
4+
var path = require('path')
5+
var express = require('express')
6+
var webpack = require('webpack')
7+
var opn = require('opn')
8+
var proxyMiddleware = require('http-proxy-middleware')
9+
var webpackConfig = process.env.NODE_ENV === 'testing'
10+
? require('./webpack.prod.conf')
11+
: require('./webpack.dev.conf')
12+
13+
// default port where dev server listens for incoming traffic
14+
var port = process.env.PORT || config.dev.port
15+
// Define HTTP proxies to your custom API backend
16+
// https://github.com/chimurai/http-proxy-middleware
17+
var proxyTable = config.dev.proxyTable
18+
19+
var app = express()
20+
var compiler = webpack(webpackConfig)
21+
22+
var devMiddleware = require('webpack-dev-middleware')(compiler, {
23+
publicPath: webpackConfig.output.publicPath,
24+
stats: {
25+
colors: true,
26+
chunks: false
27+
}
28+
})
29+
30+
var hotMiddleware = require('webpack-hot-middleware')(compiler)
31+
// force page reload when html-webpack-plugin template changes
32+
compiler.plugin('compilation', function (compilation) {
33+
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
34+
hotMiddleware.publish({ action: 'reload' })
35+
cb()
36+
})
37+
})
38+
39+
// proxy api requests
40+
Object.keys(proxyTable).forEach(function (context) {
41+
var options = proxyTable[context]
42+
if (typeof options === 'string') {
43+
options = { target: options }
44+
}
45+
app.use(proxyMiddleware(context, options))
46+
})
47+
48+
// handle fallback for HTML5 history API
49+
app.use(require('connect-history-api-fallback')())
50+
51+
// serve webpack bundle output
52+
app.use(devMiddleware)
53+
54+
// enable hot-reload and state-preserving
55+
// compilation error display
56+
app.use(hotMiddleware)
57+
58+
// serve pure static assets
59+
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
60+
app.use(staticPath, express.static('./static'))
61+
62+
module.exports = app.listen(port, function (err) {
63+
if (err) {
64+
console.log(err)
65+
return
66+
}
67+
var uri = 'http://localhost:' + port
68+
console.log('Listening at ' + uri + '\n')
69+
70+
// when env is testing, don't need open it
71+
if (process.env.NODE_ENV !== 'testing') {
72+
opn(uri)
73+
}
74+
})

build/utils.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var path = require('path')
2+
var config = require('../config')
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin')
4+
5+
exports.assetsPath = function (_path) {
6+
var assetsSubDirectory = process.env.NODE_ENV === 'production'
7+
? config.build.assetsSubDirectory
8+
: config.dev.assetsSubDirectory
9+
return path.posix.join(assetsSubDirectory, _path)
10+
}
11+
12+
exports.cssLoaders = function (options) {
13+
options = options || {}
14+
// generate loader string to be used with extract text plugin
15+
function generateLoaders (loaders) {
16+
var sourceLoader = loaders.map(function (loader) {
17+
var extraParamChar
18+
if (/\?/.test(loader)) {
19+
loader = loader.replace(/\?/, '-loader?')
20+
extraParamChar = '&'
21+
} else {
22+
loader = loader + '-loader'
23+
extraParamChar = '?'
24+
}
25+
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
26+
}).join('!')
27+
28+
// Extract CSS when that option is specified
29+
// (which is the case during production build)
30+
if (options.extract) {
31+
return ExtractTextPlugin.extract('vue-style-loader', sourceLoader)
32+
} else {
33+
return ['vue-style-loader', sourceLoader].join('!')
34+
}
35+
}
36+
37+
// http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
38+
return {
39+
css: generateLoaders(['css']),
40+
postcss: generateLoaders(['css']),
41+
less: generateLoaders(['css', 'less']),
42+
sass: generateLoaders(['css', 'sass?indentedSyntax']),
43+
scss: generateLoaders(['css', 'sass']),
44+
stylus: generateLoaders(['css', 'stylus']),
45+
styl: generateLoaders(['css', 'stylus'])
46+
}
47+
}
48+
49+
// Generate loaders for standalone style files (outside of .vue)
50+
exports.styleLoaders = function (options) {
51+
var output = []
52+
var loaders = exports.cssLoaders(options)
53+
for (var extension in loaders) {
54+
var loader = loaders[extension]
55+
output.push({
56+
test: new RegExp('\\.' + extension + '$'),
57+
loader: loader
58+
})
59+
}
60+
return output
61+
}

build/webpack.base.conf.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
var path = require('path')
2+
var config = require('../config')
3+
var utils = require('./utils')
4+
var projectRoot = path.resolve(__dirname, '../')
5+
6+
var env = process.env.NODE_ENV
7+
// check env & config/index.js to decide whether to enable CSS source maps for the
8+
// various preprocessor loaders added to vue-loader at the end of this file
9+
var cssSourceMapDev = (env === 'development' && config.dev.cssSourceMap)
10+
var cssSourceMapProd = (env === 'production' && config.build.productionSourceMap)
11+
var useCssSourceMap = cssSourceMapDev || cssSourceMapProd
12+
13+
module.exports = {
14+
entry: {
15+
app: './src/main.js'
16+
},
17+
output: {
18+
path: config.build.assetsRoot,
19+
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
20+
filename: '[name].js'
21+
},
22+
resolve: {
23+
extensions: ['', '.js', '.vue', '.json'],
24+
fallback: [path.join(__dirname, '../node_modules')],
25+
alias: {
26+
'vue$': 'vue/dist/vue.common.js',
27+
'src': path.resolve(__dirname, '../src'),
28+
'assets': path.resolve(__dirname, '../src/assets'),
29+
'components': path.resolve(__dirname, '../src/components')
30+
}
31+
},
32+
resolveLoader: {
33+
fallback: [path.join(__dirname, '../node_modules')]
34+
},
35+
module: {
36+
loaders: [
37+
{
38+
test: /\.vue$/,
39+
loader: 'vue'
40+
},
41+
{
42+
test: /\.js$/,
43+
loader: 'babel',
44+
include: projectRoot,
45+
exclude: /node_modules/
46+
},
47+
{
48+
test: /\.json$/,
49+
loader: 'json'
50+
},
51+
{
52+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
53+
loader: 'url',
54+
query: {
55+
limit: 10000,
56+
name: utils.assetsPath('img/[name].[hash:7].[ext]')
57+
}
58+
},
59+
{
60+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
61+
loader: 'url',
62+
query: {
63+
limit: 10000,
64+
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
65+
}
66+
}
67+
]
68+
},
69+
vue: {
70+
loaders: utils.cssLoaders({ sourceMap: useCssSourceMap }),
71+
postcss: [
72+
require('autoprefixer')({
73+
browsers: ['last 2 versions']
74+
})
75+
]
76+
}
77+
}

0 commit comments

Comments
 (0)