Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
init git
Browse files Browse the repository at this point in the history
  • Loading branch information
sydeEvans committed May 1, 2017
0 parents commit c9f6a97
Show file tree
Hide file tree
Showing 37 changed files with 650 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .autod.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

module.exports = {
write: true,
prefix: '^',
test: [
'test',
'benchmark',
],
dep: [
],
devdep: [
'egg-ci',
'egg-bin',
'autod',
'eslint',
'eslint-config-egg',
'webstorm-disable-index',
],
exclude: [
'./test/fixtures',
'./dist',
],
};

1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "presets": [ "es2015" ] }
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-egg"
}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
logs/
npm-debug.log
node_modules/
coverage/
.idea/
run/
.DS_Store
*.swp
dist/
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sudo: false
language: node_js
node_js:
- '6'
install:
- npm i npminstall && npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# egg-multi-boilerplate

eggjs 的 boilerplate 项目
综合了webpack,browserSync的多页应用配置


## 快速入门


如需进一步了解,参见 [egg 文档][egg]

### 本地开发
```bash
$ npm install
$ npm run dev
$ open http://localhost:7001/news
```

### 部署

线上正式环境用 `EGG_SERVER_ENV=prod` 来启动。

```bash
$ EGG_SERVER_ENV=prod npm start
```

### 单元测试
- [egg-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。
- 断言库非常推荐使用 [power-assert]
- 具体参见 [egg 文档 -单元测试](https://eggjs.org/zh-cn/core/unittest)

### 内置指令

- 使用 `npm run lint` 来做代码风格检查。
- 使用 `npm test` 来执行单元测试。
- 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod)


[egg]: https://eggjs.org
3 changes: 3 additions & 0 deletions agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

module.exports = app => {
};
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

module.exports = app => {
};
16 changes: 16 additions & 0 deletions app/controller/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

module.exports = app => {
class HomeController extends app.Controller {
* index() {
const data = { name: 'egg' };
yield this.ctx.render('home/index', data);
}

* about() {
const data = { name: 'about' };
yield this.ctx.render('about/index', data);
}
}
return HomeController;
};
10 changes: 10 additions & 0 deletions app/extend/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// this 是 helper 对象,在其中可以调用其他 helper 方法
// this.ctx => context 对象
// this.app => application 对象
const manifest = require('../../dist/manifest.json');
const url = require('url');

exports.Loader = function (resource) {
resource = manifest[resource +'.js']
return resource
};
9 changes: 9 additions & 0 deletions app/extend/helper.local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// this 是 helper 对象,在其中可以调用其他 helper 方法
// this.ctx => context 对象
// this.app => application 对象
const url = require('url');

exports.Loader = function (resource) {
const publicPath = this.app.config.browsersync.options.publicPath;
return url.resolve(publicPath,resource+'.js')
};
4 changes: 4 additions & 0 deletions app/public/about/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './index.less'
import {bar} from '../common/index'

console.log('i am about' + bar);
3 changes: 3 additions & 0 deletions app/public/about/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body{
background-color: red;
}
2 changes: 2 additions & 0 deletions app/public/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const foo = 1;
export const bar = 2;
Empty file added app/public/common/index.less
Empty file.
4 changes: 4 additions & 0 deletions app/public/home/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './index.less'
import {foo} from '../common/index'

console.log('i am home' + foo);
3 changes: 3 additions & 0 deletions app/public/home/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body{
background-color: green;
}
6 changes: 6 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = app => {
app.get('/', 'home.index');
app.get('/about', 'home.about');
};
11 changes: 11 additions & 0 deletions app/view/about/index.nj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "../layout/base.nj" %}

{% block body %}
<div>
page about !
</div>
{% endblock %}

{% block js %}
<script src="{{ helper.Loader('about') }}"></script>
{% endblock %}
11 changes: 11 additions & 0 deletions app/view/home/index.nj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "../layout/base.nj" %}

{% block body %}
<div>
page home !
</div>
{% endblock %}

{% block js %}
<script src="{{ helper.Loader('home') }}"></script>
{% endblock %}
20 changes: 20 additions & 0 deletions app/view/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title!!</title>
</head>
<body>
<div id="app">
<h1>hello world!!!!</h1>
<p @click="doSomething">test ${message}</p>
</div>
<p>egg name: {{name}}
</p>
<p>
Loader: {{helper.Loader('home')}}
</p>
<script src="https://cdn.bootcss.com/vue/2.3.0/vue.min.js"></script>
<script src="{{helper.Loader('home')}}"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions app/view/layout/base.nj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>

{% block header %}
This is the default content
{% endblock %}
</head>
<body>
{% block body %}
This is the default content
{% endblock %}

<script src="https://cdn.bootcss.com/vue/2.3.0/vue.min.js"></script>
{% block js %}
This is the default content
{% endblock %}
</body>
</html>
14 changes: 14 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
environment:
matrix:
- nodejs_version: '6'

install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && node_modules\.bin\npminstall

test_script:
- node --version
- npm --version
- npm run ci

build: off
61 changes: 61 additions & 0 deletions build/bs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const path = require("path");
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');

// return a function to ge bs config
module.exports = (config) => {
const {port,publicPath} = config;
const webpackConfig = require('./webpack.dev.config');
webpackConfig.output.publicPath = publicPath;

// Add the client which connects to our middleware
// You can use full urls like 'webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr'
// useful if you run your app from another point like django
const hotSet = `webpack-hot-middleware/client?path=http://localhost:${port}/__webpack_hmr&timeout=2000&overlay=false&reload=true`
// add dev-server entry
Object.keys(webpackConfig.entry).forEach(name => {
if (!/\./.test(name)) {
webpackConfig.entry[name] = [hotSet].concat(webpackConfig.entry[name]);
}
});

const bundler = webpack(webpackConfig);

return {
init: true,
files: [
"app/view/**/*",
// "app/public/**/*"
],
logConnections: false,

port, // bs 启动的端口

middleware: [
webpackDevMiddleware(bundler, {
// IMPORTANT: dev middleware can't access config, so we should
// provide publicPath by ourselves
publicPath: webpackConfig.output.publicPath,

// pretty colored output
stats: {colors: true},

headers: {
'X-information': 'egg-webpack-dev-server',
'Access-Control-Allow-Origin': '*',
}

// for other settings see
// http://webpack.github.io/docs/webpack-dev-middleware.html
}),

// bundler should be the same as above
webpackHotMiddleware(bundler, {
log: false,
path: "/__webpack_hmr",
heartbeat: 2000
})
]
};
};
12 changes: 12 additions & 0 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path');

module.exports = {
context: path.resolve(__dirname, '../'),

entry: {
// Add the client which connects to our middleware
home: ['./app/public/home/index.js'],
about: ['./app/public/about/index.js'],
},

};
46 changes: 46 additions & 0 deletions build/webpack.dev.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.config');

const devConfig = {

output: {
// path: path.resolve(__dirname, '../dist'),
// publicPath: '/public/',
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, '../app'),
// exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [
"style-loader",
"css-loader",
],
},
{
test: /\.less$/i,
use: [
"style-loader",
"css-loader",
"less-loader"
],
},
],
},
devtool: '#source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
],
};

module.exports = merge(baseConfig,devConfig);
Loading

0 comments on commit c9f6a97

Please sign in to comment.