Skip to content

Commit d2070af

Browse files
committed
init code
1 parent 896ea07 commit d2070af

23 files changed

+4264
-0
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["es2015", { "modules": false }],
4+
"stage-2"
5+
],
6+
"plugins": [
7+
"transform-export-extensions"
8+
]
9+
}

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/**
2+
config/**
3+
node_modules/**

.eslintrc.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var IGNORE = 0, WARN = 1, ERROR = 2, MAX_PARAMS = 4
2+
3+
module.exports = {
4+
root: true,
5+
parser: 'babel-eslint',
6+
extends: 'airbnb-base',
7+
// required to lint *.vue files
8+
plugins: [
9+
'html'
10+
],
11+
globals: {
12+
'pt': false,
13+
'TGP': false,
14+
'window': false,
15+
'pgvMain': false,
16+
'location': false,
17+
'document': false,
18+
'BJ_REPORT': false,
19+
'pgvSendClick': false,
20+
'__API_HOST__': false,
21+
'__ASSETS_PUBLIC_PATH__': false
22+
},
23+
settings: {
24+
'import/resolver': {
25+
webpack: {
26+
config: 'build/webpack.base.conf.js'
27+
}
28+
}
29+
},
30+
// add your custom rules here
31+
'rules': {
32+
'no-plusplus': IGNORE,
33+
'no-param-reassign': [ERROR, { 'props': false }],
34+
// allow debugger during development
35+
'no-debugger': process.env.NODE_ENV === 'production' ? ERROR : IGNORE,
36+
// don't require .vue extension when importing
37+
'import/extensions': [ERROR, 'always', {
38+
'js': 'never',
39+
'vue': 'never',
40+
'css': 'never',
41+
'json': 'never'
42+
}],
43+
}
44+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"vsicons.presets.angular": false
3+
}

app/index.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'use strict'
2+
const express = require('express')
3+
const path = require('path')
4+
const favicon = require('serve-favicon')
5+
const logger = require('morgan')
6+
const cookieParser = require('cookie-parser')
7+
const bodyParser = require('body-parser')
8+
const app = express()
9+
10+
const webpack = require("webpack")
11+
const webpackConfig = require('../webpack.config')
12+
const compiler = webpack(webpackConfig)
13+
14+
const devMiddleware = require('webpack-dev-middleware')(compiler, {
15+
publicPath: webpackConfig.output.publicPath,
16+
stats: {
17+
colors: true,
18+
chunks: true,
19+
lazy: false,
20+
headers: { "X-Custom-Header": "yes" },
21+
}
22+
})
23+
24+
const hotMiddleware = require('webpack-hot-middleware')(compiler)
25+
// force page reload when html-webpack-plugin template changes
26+
compiler.plugin('compilation', compilation => {
27+
compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => {
28+
hotMiddleware.publish({ action: 'reload' })
29+
cb()
30+
})
31+
})
32+
33+
//var index = require('./routes/index');
34+
//var users = require('./routes/users');
35+
const routes = require('./routes/index');
36+
// view engine setup
37+
app.set('views', path.join(__dirname, 'views'));
38+
app.set('view engine', 'ejs');
39+
40+
41+
// app.use('/', index);
42+
// app.use('/users', users);
43+
routes(app);
44+
45+
// handle fallback for HTML5 history API
46+
app.use(require('connect-history-api-fallback')())
47+
48+
// serve webpack bundle output
49+
app.use(devMiddleware)
50+
51+
// enable hot-reload and state-preserving
52+
// compilation error display
53+
app.use(hotMiddleware)
54+
55+
56+
// uncomment after placing your favicon in /public
57+
app.use(favicon(path.join(__dirname, '../public', 'favicon.ico')));
58+
app.use(logger('dev'));
59+
app.use(bodyParser.json());
60+
app.use(bodyParser.urlencoded({ extended: false }));
61+
app.use(cookieParser());
62+
63+
app.use(express.static(path.join(__dirname, '../public')));
64+
65+
66+
67+
// catch 404 and forward to error handler
68+
app.use(function(req, res, next) {
69+
var err = new Error('Not Found');
70+
err.status = 404;
71+
next(err);
72+
});
73+
74+
// error handler
75+
app.use(function(err, req, res, next) {
76+
// set locals, only providing error in development
77+
res.locals.message = err.message;
78+
res.locals.error = req.app.get('env') === 'development' ? err : {};
79+
80+
// render the error page
81+
res.status(err.status || 500);
82+
res.render('error');
83+
});
84+
85+
module.exports = app;

app/routes/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*var express = require('express');
2+
var router = express.Router();
3+
router.get('/', function(req, res, next) {
4+
res.render('index', { title: 'Express' });
5+
});
6+
module.exports = router;
7+
*/
8+
module.exports = function(app) {
9+
app.get('/hello', function(req, res) {
10+
res.render('index', { title: 'ExpressZ', hello: '<h1>Hello Title!</h1>' });
11+
});
12+
app.get('/test', function(req, res) {
13+
res.send('Hello World!');
14+
});
15+
}

app/routes/users.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var express = require('express');
2+
var router = express.Router();
3+
4+
/* GET users listing. */
5+
router.get('/', function(req, res, next) {
6+
res.send('respond with a resource');
7+
});
8+
9+
module.exports = router;

app/views/error.ejs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1><%= message %></h1>
2+
<h2><%= error.status %></h2>
3+
<pre><%= error.stack %></pre>

app/views/footer.ejs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>This is footer!</p>
2+
</body>
3+
</html>

app/views/header.ejs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title><%= title %></title>
5+
<link rel='stylesheet' href='/stylesheets/style.css' />
6+
</head>
7+
<body>
8+
<p>This is header!</p>

app/views/index.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%- include header %>
2+
<h1><%= title %></h1>
3+
<p>Welcome to <%= title %></p>
4+
<%- hello %>
5+
<%- include footer %>

bin/www.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app/index');
8+
var debug = require('debug')('blog:server');
9+
var http = require('http');
10+
const pkg = require('../package.json')
11+
const opn = require('opn')
12+
13+
/**
14+
* Get port from environment and store in Express.
15+
*/
16+
17+
var port = normalizePort(process.env.PORT || '3000');
18+
app.set('port', port);
19+
20+
/**
21+
* Create HTTP server.
22+
*/
23+
24+
var server = http.createServer(app);
25+
26+
/**
27+
* Listen on provided port, on all network interfaces.
28+
*/
29+
30+
server.listen(port);
31+
server.on('error', onError);
32+
server.on('listening', onListening);
33+
34+
/**
35+
* Normalize a port into a number, string, or false.
36+
*/
37+
38+
function normalizePort(val) {
39+
var port = parseInt(val, 10);
40+
41+
if (isNaN(port)) {
42+
// named pipe
43+
return val;
44+
}
45+
46+
if (port >= 0) {
47+
// port number
48+
return port;
49+
}
50+
51+
return false;
52+
}
53+
54+
/**
55+
* Event listener for HTTP server "error" event.
56+
*/
57+
58+
function onError(error) {
59+
if (error.syscall !== 'listen') {
60+
throw error;
61+
}
62+
63+
var bind = typeof port === 'string' ?
64+
'Pipe ' + port :
65+
'Port ' + port;
66+
67+
// handle specific listen errors with friendly messages
68+
switch (error.code) {
69+
case 'EACCES':
70+
console.error(bind + ' requires elevated privileges');
71+
process.exit(1);
72+
break;
73+
case 'EADDRINUSE':
74+
console.error(bind + ' is already in use');
75+
process.exit(1);
76+
break;
77+
default:
78+
throw error;
79+
}
80+
}
81+
82+
/**
83+
* Event listener for HTTP server "listening" event.
84+
*/
85+
86+
function onListening() {
87+
var addr = server.address();
88+
var bind = typeof addr === 'string' ?
89+
'pipe ' + addr :
90+
'port ' + addr.port;
91+
debug('Listening on ' + bind);
92+
debug('Listening at ' + pkg.homepage + '\n')
93+
opn(pkg.homepage)
94+
}

client/entry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// require("!style-loader!css-loader!../css/style.css"); // 载入 style.css
2+
require("./foo/style.css"); // 载入 style.css
3+
document.write('It works again.\n<br>');
4+
document.write(require('./foo/module.js')) // 添加模块

client/foo/module.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'It works from bax/module.js.'

client/foo/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
color: gainsboro;
3+
background: darkolivegreen;
4+
}

client/webpack/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export parts from './parts';
2+
export utils from './utils';

client/webpack/parts.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const webpack = require('webpack');
2+
3+
exports.devServer = function(options) {
4+
return {
5+
watchOptions: {
6+
// Delay the rebuild after the first change
7+
aggregateTimeout: 300,
8+
// Poll using interval (in ms, accepts boolean too)
9+
poll: 1000
10+
}, //*/
11+
devServer: {
12+
// Enable history API fallback so HTML5 History API based
13+
// routing works. This is a good default that will come
14+
// in handy in more complicated setups.
15+
historyApiFallback: true,
16+
17+
// Unlike the cli flag, this doesn't set
18+
// HotModuleReplacementPlugin!
19+
hot: true,
20+
inline: true,
21+
// Display only errors to reduce the amount of output.
22+
stats: 'errors-only',
23+
// Parse host and port from env to allow customization.
24+
//
25+
// If you use Vagrant or Cloud9, set
26+
// host: options.host || '0.0.0.0';
27+
//
28+
// 0.0.0.0 is available to all network devices
29+
// unlike default `localhost`.
30+
host: options.host || '0.0.0.0', // Defaults to `localhost`
31+
port: options.port || 8080 // Defaults to 8080
32+
},
33+
plugins: [
34+
// Enable multi-pass compilation for enhanced performance
35+
// in larger projects. Good default.
36+
new webpack.HotModuleReplacementPlugin({
37+
multiStep: true
38+
})
39+
]
40+
};
41+
}

0 commit comments

Comments
 (0)