From 2dbc4413edf6ce4752d11730377fce9040d3362c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E5=A5=87=E8=BE=89?= Date: Thu, 18 Feb 2016 10:48:43 +0800 Subject: [PATCH] init --- .editorconfig | 12 ++++++ .gitignore | 5 +++ .jshintrc | 21 ++++++++++ bower.json | 6 +++ gulpfile.js | 59 ++++++++++++++++++++++++++++ package.json | 17 ++++++++ src/index.html | 12 ++++++ src/javascripts/app.js | 10 +++++ src/javascripts/components/title.js | 10 +++++ src/javascripts/templates/title.html | 1 + src/stylesheets/app.css | 0 11 files changed, 153 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 bower.json create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/index.html create mode 100644 src/javascripts/app.js create mode 100644 src/javascripts/components/title.js create mode 100644 src/javascripts/templates/title.html create mode 100644 src/stylesheets/app.css diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5760be5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7754940 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +temp +dist +node_modules +npm-debug.log +.sass-cache diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..0cd291c --- /dev/null +++ b/.jshintrc @@ -0,0 +1,21 @@ +{ + "node": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "white": true +} diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..2b4eb38 --- /dev/null +++ b/bower.json @@ -0,0 +1,6 @@ +{ + "name": "package", + "version": "0.0.0", + "dependencies": {} +} + diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..f5b884b --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,59 @@ +'use strict'; +var gulp = require('gulp'); +var browserSync = require('browser-sync'); +var rimraf = require('gulp-rimraf'); +var source = require('vinyl-source-stream'); +var browserify = require('browserify'); +var html2react = require('gulp-html2react'); +var changed = require('gulp-changed'); +var debowerify = require('debowerify'); + +gulp.task('clean', function() { + return gulp.src('dist', { + read: false + }) + .pipe(rimraf({ + force: true + })); +}); + +gulp.task('browserSync', function() { + browserSync.init(['dist/**'], { + server: { + baseDir: 'dist' + } + }); +}); + +gulp.task('react', function() { + return gulp.src('src/javascripts/templates/**/*.html') + .pipe(html2react()) + .pipe(gulp.dest('temp/javascripts/templates')); +}); + +gulp.task('copy_js', function() { + var files = ['src/javascripts/**/*.js']; + return gulp.src(files).pipe(gulp.dest('temp/javascripts')); +}); + +gulp.task('copy', ['copy_js'], function() { + var files = ['src/**/*', '!src/javascripts', '!src/javascripts/**/*']; + var DEST = 'dist'; + + return gulp.src(files).pipe(changed(DEST)).pipe(gulp.dest(DEST)); +}); + +// using vinyl-source-stream: +gulp.task('browserify', ['copy', 'react'], function() { + var bundleStream = browserify('./temp/javascripts/app.js').transform(debowerify).bundle(); + bundleStream + .pipe(source('./javascripts/app.js')) + .pipe(gulp.dest('./dist/')); +}); + +gulp.task('default', ['browserify', 'browserSync'], function() { + gulp.watch('src/*.html', ['copy']); + gulp.watch('src/stylesheets/**/*', ['copy']); + + gulp.watch('src/javascripts/**/*', ['browserify']); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..817b92f --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "package", + "version": "0.0.0", + "devDependencies": { + "gulp": "~3.8.8", + "browser-sync": "~2.6.9", + "debowerify": "^0.8.2", + "gulp-changed": "^1.0.0", + "gulp-html2react": "^0.1.6", + "gulp-rimraf": "~0.1.1", + "vinyl-source-stream": "~1.0.0", + "browserify": "~6.0.3" + }, + "dependencies": { + "react": "~0.13.2" + } +} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..ec59cdc --- /dev/null +++ b/src/index.html @@ -0,0 +1,12 @@ + + + + + Document + + +

welcome to react

+
+ + + \ No newline at end of file diff --git a/src/javascripts/app.js b/src/javascripts/app.js new file mode 100644 index 0000000..3f71eb8 --- /dev/null +++ b/src/javascripts/app.js @@ -0,0 +1,10 @@ +var React = require('react'); + +var Title = require('./components/title'); + +React.render( + React.createElement(Title, { + name: 'John Cena' + }), + document.getElementById('react') +); diff --git a/src/javascripts/components/title.js b/src/javascripts/components/title.js new file mode 100644 index 0000000..2a5ba47 --- /dev/null +++ b/src/javascripts/components/title.js @@ -0,0 +1,10 @@ +var React = require('react'); +var titleTemplate = require('.././templates/title'); + +var Title = React.createClass({ + render: function() { + return titleTemplate.call(this);; + } +}); + +module.exports = Title; diff --git a/src/javascripts/templates/title.html b/src/javascripts/templates/title.html new file mode 100644 index 0000000..2767a8a --- /dev/null +++ b/src/javascripts/templates/title.html @@ -0,0 +1 @@ +

{this.props.name}

diff --git a/src/stylesheets/app.css b/src/stylesheets/app.css new file mode 100644 index 0000000..e69de29