Skip to content

Commit c910f32

Browse files
committed
初始化项目
0 parents  commit c910f32

26 files changed

+550
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
/node_modules
3+
/build
4+
/index.html
5+
/lib

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
/build
3+
/gulpfile.coffee
4+
/webpack.*
5+
/template.cirru
6+
/index.html

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
CNode.js 中文导航
3+
----
4+
5+
访问:
6+
7+
* http://nav.cnodejs.org (还未完成跳转)
8+
* http://nav.nodejs-china.org
9+
10+
### Develop
11+
12+
静态文件 `index.html` 建议用 Nginx 站点打开, 或者其他服务器.
13+
开发环境基于 Webpack 做了热替换:
14+
15+
```bash
16+
npm i
17+
gulp dev
18+
```
19+
20+
打包命令, `static` 只合并代码生成 HTML, `ws` 进一步压缩代码.
21+
22+
```bash
23+
NODE_ENV=static gulp build # not minified
24+
npm run static
25+
26+
NODE_ENV=ws gulp build
27+
npm run ws
28+
```
29+
30+
通过 rsync 上传服务器, 不过需要修改一下文件里的配置:
31+
32+
```bash
33+
gulp rsync
34+
```
35+
36+
### License
37+
38+
MIT

config/default.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
module.exports =
3+
env: 'dev'
4+
webpackDevPort: 8011
5+
isMinified: no

config/dev.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
module.exports = {}

config/static.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
module.exports =
3+
env: 'static'
4+
isMinified: no

config/ws.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
module.exports =
3+
env: 'ws'
4+
isMinified: yes

entry/template.coffee

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
stir = require 'stir-template'
3+
React = require 'react'
4+
config = require 'config'
5+
6+
assetLinks = require '../packing/asset-links'
7+
8+
Page = React.createFactory require '../src/page'
9+
10+
{html, head, title, body, meta, script, link, div, a, span, style} = stir
11+
12+
module.exports = (data) ->
13+
14+
stir.render stir.doctype(),
15+
html null,
16+
head null,
17+
title null, "CNode.js 导航"
18+
meta charset: 'utf-8'
19+
link rel: 'icon', href: 'https://dn-cnodestatic.qbox.me/public/images/cnode_icon_32.png'
20+
if assetLinks.style?
21+
link rel: 'stylesheet', href: assetLinks.style
22+
script src: assetLinks.vendor, defer: true
23+
script src: assetLinks.main, defer: true
24+
style null, 'body * {box-sizing: border-box;}'
25+
body style: "margin:0;",
26+
div id: 'app',
27+
React.renderToString Page()

gulpfile.coffee

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
fs = require 'fs'
3+
gulp = require 'gulp'
4+
gutil = require 'gulp-util'
5+
config = require 'config'
6+
webpack = require 'webpack'
7+
sequence = require 'run-sequence'
8+
WebpackDevServer = require 'webpack-dev-server'
9+
10+
gulp.task 'script', ->
11+
coffee = require('gulp-coffee')
12+
gulp
13+
.src 'src/*.coffee'
14+
.pipe coffee()
15+
.pipe gulp.dest('lib/')
16+
17+
gulp.task 'rsync', (cb) ->
18+
wrapper = require 'rsyncwrapper'
19+
wrapper.rsync
20+
ssh: true
21+
src: ['build/*']
22+
recursive: true
23+
args: ['--verbose']
24+
dest: 'aliyun:/home/chen/repo/nav.cnodejs.org/'
25+
deleteAll: true
26+
, (error, stdout, stderr, cmd) ->
27+
if error?
28+
throw error
29+
console.error stderr
30+
console.log cmd
31+
cb()
32+
33+
gulp.task 'html', (cb) ->
34+
html = require('./entry/template')
35+
fs = require('fs')
36+
fs.writeFile 'build/index.html', html(), cb
37+
38+
gulp.task 'del', (cb) ->
39+
del = require('del')
40+
del 'build/**/*', cb
41+
42+
# webpack tasks
43+
44+
gulp.task 'webpack-dev', (cb) ->
45+
webpackDev = require './packing/webpack-dev'
46+
webpackServer =
47+
publicPath: '/'
48+
hot: true
49+
stats:
50+
colors: true
51+
info =
52+
__dirname: __dirname
53+
env: config.env
54+
55+
compiler = webpack (webpackDev info)
56+
server = new WebpackDevServer compiler, webpackServer
57+
58+
server.listen config.webpackDevPort, 'localhost', (err) ->
59+
if err?
60+
throw new gutil.PluginError("webpack-dev-server", err)
61+
gutil.log "[webpack-dev-server] is running..."
62+
cb()
63+
64+
gulp.task 'webpack-build', (cb) ->
65+
webpackBuild = require './packing/webpack-build'
66+
info =
67+
__dirname: __dirname
68+
isMinified: config.isMinified
69+
useCDN: config.useCDN
70+
cdn: config.cdn
71+
env: config.env
72+
webpack (webpackBuild info), (err, stats) ->
73+
if err
74+
throw new gutil.PluginError("webpack", err)
75+
gutil.log '[webpack]', stats.toString()
76+
fileContent = JSON.stringify stats.toJson().assetsByChunkName
77+
fs.writeFileSync 'packing/assets.json', fileContent
78+
cb()
79+
80+
# aliases
81+
82+
gulp.task 'dev', (cb) ->
83+
sequence 'html', 'webpack-dev', cb
84+
85+
gulp.task 'build', (cb) ->
86+
gutil.log gutil.colors.yellow("Running Gulp in `#{config.env}` mode!")
87+
sequence 'del', 'webpack-build', 'html', cb

package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "coffee-webpack-starter",
3+
"version": "0.0.1",
4+
"description": "Component starter kit for Talk by Teambition",
5+
"main": "lib/index.js",
6+
"dependencies": {
7+
"classnames": "^1.2.0",
8+
"hsl": "^0.1.1",
9+
"react": "^0.13.1"
10+
},
11+
"devDependencies": {
12+
"autoprefixer-loader": "^2.0.0",
13+
"coffee-loader": "^0.7.2",
14+
"coffee-script": "^1.9.1",
15+
"config": "^1.17.1",
16+
"css-loader": "^0.10.1",
17+
"del": "^1.1.1",
18+
"extract-text-webpack-plugin": "^0.8.2",
19+
"file-loader": "^0.8.4",
20+
"gulp": "^3.8.11",
21+
"gulp-coffee": "^2.3.1",
22+
"gulp-util": "^3.0.7",
23+
"less": "^2.5.1",
24+
"less-loader": "^2.2.0",
25+
"rsyncwrapper": "^0.4.3",
26+
"run-sequence": "^1.0.2",
27+
"skip-webpack-plugin": "^0.1.1",
28+
"stir-template": "^0.1.4",
29+
"style-loader": "^0.10.2",
30+
"url-loader": "^0.5.6",
31+
"webpack": "^1.8.4",
32+
"webpack-dev-server": "^1.8.0"
33+
},
34+
"scripts": {
35+
"test": "echo \"Error: no test specified\" && exit 1",
36+
"static": "NODE_ENV=static gulp build",
37+
"ws": "NODE_ENV=ws gulp build"
38+
},
39+
"keywords": [
40+
"react-component"
41+
],
42+
"author": "Teambition",
43+
"license": "MIT",
44+
"repository": {
45+
"type": "git",
46+
"url": "https://github.com/teambition/coffee-webpack-starter.git"
47+
},
48+
"bugs": {
49+
"url": "https://github.com/teambition/coffee-webpack-starter/issues"
50+
},
51+
"homepage": "https://github.com/teambition/coffee-webpack-starter"
52+
}

packing/asset-links.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
config = require 'config'
3+
4+
if config.env is 'dev'
5+
module.exports =
6+
main: "http://localhost:#{config.webpackDevPort}/main.js"
7+
vendor: "http://localhost:#{config.webpackDevPort}/vendor.js"
8+
style: null
9+
else
10+
assets = require '../packing/assets'
11+
prefix = ''
12+
13+
module.exports =
14+
main: "#{prefix}#{assets.main}"
15+
style: null
16+
vendor: "#{prefix}#{assets.vendor}"

packing/assets.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"main":"main.83d6de6a.js","vendor":"vendor.5bdb61b6.js"}

packing/webpack-build.coffee

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
fs = require('fs')
3+
path = require 'path'
4+
webpack = require('webpack')
5+
SkipPlugin = require 'skip-webpack-plugin'
6+
ExtractTextPlugin = require 'extract-text-webpack-plugin'
7+
8+
webpackDev = require('./webpack-dev')
9+
10+
fontName = 'fonts/[name].[ext]'
11+
12+
module.exports = (info) ->
13+
webpackConfig = webpackDev info
14+
publicPath = ''
15+
16+
# return
17+
entry:
18+
vendor: []
19+
main: ['./src/main']
20+
output:
21+
path: path.join info.__dirname, 'build/'
22+
filename: '[name].[chunkhash:8].js'
23+
publicPath: publicPath
24+
resolve: webpackConfig.resolve
25+
module:
26+
loaders: [
27+
{test: /\.coffee$/, loader: 'coffee'}
28+
{test: /\.less$/, loader: 'style!css!less'}
29+
{test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css!autoprefixer')}
30+
{test: /\.(eot|woff|woff2|ttf|svg)((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 100, name: fontName}}
31+
]
32+
plugins: [
33+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.[chunkhash:8].js')
34+
if info.isMinified
35+
new webpack.optimize.UglifyJsPlugin(compress: {warnings: false}, sourceMap: false)
36+
else
37+
new SkipPlugin info: 'UglifyJsPlugin skipped'
38+
new ExtractTextPlugin("style.[chunkhash:8].css")
39+
]

packing/webpack-dev.coffee

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
fs = require('fs')
3+
path = require 'path'
4+
config = require 'config'
5+
webpack = require 'webpack'
6+
7+
fontName = 'fonts/[name].[ext]'
8+
9+
module.exports = (info) ->
10+
entry:
11+
vendor: [
12+
"webpack-dev-server/client?http://localhost:#{config.webpackDevPort}"
13+
'webpack/hot/dev-server'
14+
'react'
15+
]
16+
main: [
17+
'./src/main'
18+
]
19+
output:
20+
path: path.join info.__dirname, 'build'
21+
filename: '[name].js'
22+
publicPath: "http://localhost:#{config.webpackDevPort}/"
23+
resolve: extensions: ['.js', '.coffee', '']
24+
module:
25+
loaders: [
26+
{test: /\.coffee$/, loader: 'coffee'}
27+
{test: /\.less$/, loader: 'style!css!less'}
28+
{test: /\.css$/, loader: 'style!css!autoprefixer'}
29+
{test: /\.(eot|woff|woff2|ttf|svg)((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 100, name: fontName}}
30+
]
31+
plugins: [
32+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js')
33+
new webpack.HotModuleReplacementPlugin()
34+
]

src/app/communities.coffee

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
React = require 'react'
3+
4+
style = require '../style'
5+
6+
link = require './link'
7+
8+
{div, a} = React.DOM
9+
10+
module.exports = React.createClass
11+
displayName: 'app-communities'
12+
13+
render: ->
14+
div style: null,
15+
div style: style.widget.title, '社区'
16+
link 'CNode.js 中文社区', 'http://cnodejs.org'
17+
link 'CNode.js 中文社区, 微博', 'http://weibo.com/cnodejs'
18+
div style: style.widget.group, 'QQ 群: ???'
19+
div style: style.widget.group, '微信: ???'

src/app/content.coffee

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
React = require 'react'
3+
4+
style = require '../style'
5+
6+
Resources = React.createFactory require './resources'
7+
Communities = React.createFactory require './communities'
8+
9+
{div} = React.DOM
10+
11+
module.exports = React.createClass
12+
displayName: 'app-communities'
13+
14+
render: ->
15+
div style: style.layout.content,
16+
div style: style.layout.column,
17+
Resources()
18+
div style: style.layout.column,
19+
Communities()

src/app/footer.coffee

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
React = require 'react'
3+
4+
style = require '../style'
5+
6+
{div} = React.DOM
7+
8+
module.exports = React.createClass
9+
displayName: 'footer'
10+
11+
render: ->
12+
div style: style.layout.footer,
13+
'浙ICP备14043687号-2'

0 commit comments

Comments
 (0)