Skip to content

Commit 40d62db

Browse files
committed
add test page
1 parent 6509d42 commit 40d62db

File tree

5 files changed

+120
-13
lines changed

5 files changed

+120
-13
lines changed

app/js/app-routes.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict"
2+
3+
import {Route, Router} from 'react-router'
4+
import createHistory from 'history/lib/createHashHistory'
5+
6+
const history = createHistory({ queryKey: false })
7+
let menulist = []
8+
9+
// function addMenu(list) {
10+
// list.forEach(function (menu, index) {
11+
// if (menu.component) {
12+
// menulist.push(
13+
// <Route key={index} path={menu.path} component={menu.component} />
14+
// )
15+
// }
16+
// })
17+
// }
18+
// require('./menulist').forEach(function (list) {
19+
// addMenu(list)
20+
// })
21+
22+
// import Master from './pages/master.jsx'
23+
// import Home from './pages/home.jsx'
24+
import Home from './test.jsx'
25+
26+
/*
27+
<Route path="/home" component={Home} />
28+
{menulist}
29+
<Route path="/build" component={require('./pages/build.jsx')} />
30+
*/
31+
32+
const AppRoutes = (
33+
<Router history={history}>
34+
<Route path="/" indexRoute={{component: Home}} component={Home}>
35+
36+
</Route>
37+
</Router>
38+
)
39+
40+
export default AppRoutes

app/js/app.jsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict"
2+
3+
// global.uiRequire = function (src) {
4+
// if (src) {
5+
// return require('../../src/' + src)
6+
// } else {
7+
// return require('../../src/')
8+
// }
9+
// }
10+
//
11+
// import ReactDOM from 'react-dom'
12+
// const AppRoutes = require('./app-routes.jsx')
13+
//
14+
// ReactDOM.render(
15+
// AppRoutes,
16+
// document.getElementById('body')
17+
// )
18+
19+
import ReactDOM from 'react-dom'
20+
const AppRoutes = require('./app-routes.jsx')
21+
22+
console.log('helloooo')
23+
24+
ReactDOM.render(
25+
AppRoutes,
26+
document.body
27+
)
28+
29+
// document.addEventListener('DOMContentLoaded', function() {
30+
// Router.run(routes,
31+
// Router.HashLocation,
32+
// function(Root, state) {
33+
// React.render(<Root />, document.body);
34+
// });
35+
// });
36+
37+
38+
// static files
39+
// require('file?name=index.html!../index.html')
40+
// require('../json/countries.json')
41+
// require('../json/form.json')
42+
// require('../json/text-value.json')
43+
// require('../json/tree.json')

app/js/test.jsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
4+
import React from 'react'
5+
6+
console.log('tests')
7+
8+
var Component = React.createClass({
9+
render: function() {
10+
return (
11+
<div className="test">
12+
<p>test</p>
13+
</div>
14+
);
15+
}
16+
});
17+
18+
export default Component

gulpfile.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var del = require('del');
1111
var runSequence = require('run-sequence');
1212
var browserSync = require('browser-sync');
1313
var browserify = require('browserify');
14+
var babelify = require('babelify');
1415
var watchify = require('watchify');
1516
var source = require('vinyl-source-stream');
1617
var buffer = require('vinyl-buffer');
@@ -30,6 +31,7 @@ var AUTOPREFIXER_BROWSERS = [
3031
];
3132

3233
var paths = {
34+
bootjs: 'app.jsx',
3335
dist: {
3436
base: 'dist',
3537
js: 'dist/js',
@@ -105,7 +107,7 @@ gulp.task('copy:venders', function () {
105107
.pipe($.size({title: 'copy:venders'}));
106108
});
107109
// 拷贝相关资源
108-
gulp.task('copy', function () {
110+
gulp.task('copy', ['copy:venders'], function () {
109111
return gulp.src([
110112
'app/**/*',
111113
'!app/*.html',
@@ -168,12 +170,14 @@ gulp.task('styles', function () {
168170
.pipe($.size({title: 'styles'}));
169171
});
170172

171-
// 打包 Common JS 模块,此处使用 ES6 的话,需要调整设置
173+
// 打包 Common JS 模块,此处使用 ES6 的话,选用 babel 编译 ES6,需要调整设置
174+
// TODO: 是否将 browserify 改为使用 webpack 来实现
172175
var b = browserify({
173176
cache: {},
174177
packageCache: {},
175-
entries: ['./app/js/app.js'],
178+
entries: [('./app/js/' + paths.bootjs)],
176179
debug: !isProduction,
180+
// extensions: [".jsx"],
177181
transform: ['babelify']
178182
});
179183

@@ -204,12 +208,13 @@ b.transform('browserify-shim', {global: true});
204208

205209
var bundle = function() {
206210
var s = (
207-
b.bundle()
211+
b.transform(babelify).bundle()
208212
.on('error', $.util.log.bind($.util, 'Browserify Error'))
209-
.pipe(source('app.js'))
213+
.pipe( source(paths.bootjs) )
210214
.pipe(buffer())
211215
// .pipe($.sourcemaps.init())
212216
// .pipe($.sourcemaps.write("."))
217+
.pipe($.rename('app.js'))
213218
.pipe(gulp.dest(paths.dist.js))
214219
.pipe($.size({title: 'script'}))
215220
);
@@ -261,13 +266,13 @@ gulp.task('watch', function() {
261266
// 启动预览服务,并监视 Dist 目录变化自动刷新浏览器
262267
gulp.task('dev', ['default', 'watch'], function () {
263268
browserSync({
264-
// port: 5000, //默认3000
265-
// ui: { //更改默认端口weinre 3001
266-
// port: 5001,
267-
// weinre: {
268-
// port: 9090
269-
// }
270-
// },
269+
port: 5000, //默认3000
270+
ui: { //更改默认端口weinre 3001
271+
port: 5001,
272+
weinre: {
273+
port: 9090
274+
}
275+
},
271276
// server: {
272277
// baseDir: 'dist/docs'
273278
// },
@@ -284,7 +289,7 @@ gulp.task('dev', ['default', 'watch'], function () {
284289
gulp.task('default', function (cb) {
285290
console.log('生产环境:' + isProduction);
286291
//runSequence('clean', ['styles', 'jshint', 'html', 'images', 'copy', 'browserify'], cb);
287-
runSequence('clean', ['styles', 'html', 'images', 'copy:venders', 'copy', 'browserify'], cb);
292+
runSequence('clean', ['styles', 'html', 'images', 'copy', 'browserify'], cb);
288293
});
289294

290295

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
},
106106
"browser": {},
107107
"browserify-shim": {
108+
"react-dom": "global:ReactDOM",
108109
"react": "global:React"
109110
}
110111
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy