Skip to content

Commit df7cacf

Browse files
committed
Merge pull request #8 from jkazama/topic/7
Babel 6 対応 fix #7
2 parents 4677339 + b233a1c commit df7cacf

File tree

5 files changed

+212
-184
lines changed

5 files changed

+212
-184
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "sample-ui-react",
3-
"version": "0.1.5",
3+
"version": "0.2.0",
44
"main": "main.js",
55
"dependencies": {
66
"lodash": "~3.10.1",
77
"moment": "~2.10.6",
88
"bootstrap-sass-official": "~3.3.6",
99
"fontawesome": "~4.5.0",
10-
"react": "~0.14.6",
10+
"react": "~0.14.7",
1111
"react-router": "~0.13.5",
1212
"eventEmitter": "~4.3.0",
1313
"flux": "~2.1.1"

gulpfile.babel.js

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
const root = {
2+
src: `${__dirname}/source`,
3+
dist: `${__dirname}/public`,
4+
tmp: `${__dirname}/tmp`
5+
}
6+
7+
const paths = {
8+
src: {
9+
root: `${root.src}`,
10+
html: `${root.src}/html`,
11+
js: `${root.src}/js`,
12+
css: `${root.src}/css`,
13+
static: `${root.src}/static`
14+
},
15+
dist: {
16+
root: `${root.dist}`,
17+
js: `${root.dist}/js`,
18+
css: `${root.dist}/css`,
19+
font: `${root.dist}/fonts`
20+
},
21+
bower: {
22+
component: `${__dirname}/bower_components`,
23+
file: `${__dirname}/bower.json`
24+
}
25+
}
26+
const resource = {
27+
src: {
28+
jade: `${paths.src.html}/**/*.jade`,
29+
webpack: {
30+
babel: `${paths.src.js}/**/*.js`,
31+
vue: `${paths.src.js}/**/*.vue`
32+
},
33+
sass: `${paths.src.css}/**/*.s+(a|c)ss`,
34+
static: `${paths.src.static}/**/*`,
35+
font: `${paths.bower.component}/fontawesome/fonts/**/*`
36+
}
37+
}
38+
39+
import gulp from 'gulp'
40+
import gulpLoaderPlugins from 'gulp-load-plugins'
41+
import del from 'del'
42+
import path from 'path'
43+
import bower from 'bower'
44+
import bowerFiles from 'main-bower-files'
45+
import webpack from 'webpack'
46+
import webpackStream from 'webpack-stream'
47+
import runSequence from 'run-sequence'
48+
import browserSyncTool from 'browser-sync'
49+
import RevAll from 'gulp-rev-all'
50+
51+
const $ = gulpLoaderPlugins()
52+
const browserSync = browserSyncTool.create()
53+
54+
let production = false
55+
56+
// build and watch for developer
57+
gulp.task('default', ['build', 'server'])
58+
59+
//## build for developer
60+
gulp.task('build', (callback) =>
61+
runSequence('clean', 'bower', ['build:jade', 'build:sass', 'build:webpack', 'build:static'], callback)
62+
)
63+
64+
//## build production
65+
gulp.task('build-prod', (callback) =>
66+
runSequence('production', 'build', 'revision', callback)
67+
)
68+
69+
// clean dist
70+
gulp.task('clean', () =>
71+
del.sync([`${paths.dist.root}/*`, `!${paths.dist.root}/.git*`], { force: true })
72+
)
73+
74+
// production option
75+
gulp.task('production', () => production = true )
76+
77+
// support Resource Revision
78+
gulp.task('revision', (callback) =>
79+
runSequence('revision:clean', 'revision:append', 'clean', 'revision:copy', 'revision:clean', callback)
80+
)
81+
82+
// build Vendor UI Library (bower.json) [Load/Concat]
83+
gulp.task('bower', () => {
84+
bower.commands.install().on('end', () => {
85+
const filterCss = ['**/bootstrap-datepicker3.css']
86+
gulp.src(bowerFiles({filter: filterCss}))
87+
.pipe($.concat('vendor.css'))
88+
.pipe($.pleeease())
89+
.pipe(gulp.dest(paths.dist.css))
90+
gulp.src(resource.src.font) // for font-awesome
91+
.pipe(gulp.dest(paths.dist.font))
92+
const filterJs = (file) => { // for bootstrap-sass-official
93+
return /.*\.js/.test(file) && ($.slash(file).indexOf('/bootstrap/') == -1)
94+
}
95+
const appendJs = path.join(paths.bower.component, 'react/react-dom.js')
96+
gulp.src(bowerFiles({filter: filterJs}).concat(appendJs))
97+
.pipe($.concat('vendor.js'))
98+
.pipe($.if(production, $.uglify()))
99+
.pipe(gulp.dest(paths.dist.js))
100+
})
101+
})
102+
103+
// compile Webpack [ ES6(Babel) / Vue -> SPA(main.js) ]
104+
gulp.task('build:webpack', () => {
105+
process.env.NODE_ENV = (production == true) ? 'production' : 'development'
106+
let plugins = [
107+
new webpack.ResolverPlugin(new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])),
108+
new webpack.optimize.DedupePlugin()
109+
]
110+
if (production) plugins.push(new webpack.optimize.UglifyJsPlugin({compress: { warnings: false }}))
111+
gulp.src([resource.src.webpack.babel, resource.src.webpack.vue])
112+
.pipe($.plumber())
113+
.pipe(webpackStream({
114+
entry: `${paths.src.js}/main.js`,
115+
output: {filename: 'bundler.js'},
116+
watch: !production,
117+
module: {
118+
loaders: [
119+
{test: /\.(js|jsx)$/, loader: 'babel', query: {presets: ['es2015', 'react']}},
120+
{test: /\.jade$/, loader: "react-jade-loader"}
121+
]
122+
},
123+
resolve: {
124+
modulesDirectories: ['node_modules', 'bower_components', paths.src.js],
125+
extensions: ['', '.js', ".jsx", ".jade"]
126+
},
127+
resolveLoader: {
128+
modulesDirectories: ['node_modules', `${__dirname}/webpack/loaders`]
129+
},
130+
plugins: plugins
131+
}, webpack))
132+
.pipe(gulp.dest(paths.dist.js))
133+
.pipe(browserSync.stream())
134+
})
135+
136+
// compile Jade -> HTML
137+
gulp.task('build:jade', () => {
138+
gulp.src(resource.src.jade)
139+
.pipe($.plumber())
140+
.pipe($.jade())
141+
.pipe($.htmlhint())
142+
.pipe($.htmlhint.reporter())
143+
.pipe(gulp.dest(paths.dist.root))
144+
.pipe(browserSync.stream())
145+
})
146+
147+
// compile Sass -> CSS
148+
// check https://github.com/sasstools/sass-lint/pull/168
149+
gulp.task('build:sass', () => {
150+
gulp.src(resource.src.sass)
151+
.pipe($.plumber())
152+
// .pipe($.sassLint())
153+
// .pipe($.sassLint.format())
154+
// .pipe($.sassLint.failOnError())
155+
.pipe($.sass())
156+
.pipe($.concat('style.css'))
157+
.pipe($.pleeease())
158+
.pipe(gulp.dest(paths.dist.css))
159+
.pipe(browserSync.stream())
160+
})
161+
162+
// copy Static Resource
163+
gulp.task('build:static', () => {
164+
gulp.src(resource.src.static)
165+
.pipe(gulp.dest(paths.dist.root))
166+
})
167+
168+
// run Development Web Server (BrowserSync) [localhost:3000]
169+
gulp.task('server', () => {
170+
browserSync.init({
171+
server: {baseDir: paths.dist.root},
172+
notify: false
173+
})
174+
// watch for source
175+
gulp.watch(paths.bower.file, ['bower'])
176+
gulp.watch(resource.src.jade, ['build:jade'])
177+
gulp.watch(resource.src.sass, ['build:sass'])
178+
gulp.watch(resource.src.static, ['build:static'])
179+
})
180+
181+
// append Resource Revision
182+
gulp.task('revision:clean', () => {
183+
del.sync([root.tmp], { force: true })
184+
})
185+
186+
gulp.task('revision:append', () => {
187+
let revAll = new RevAll({dontRenameFile: [/^\/favicon.ico$/g, '.html']})
188+
gulp.src(`${paths.dist.root}/**/*`)
189+
.pipe(revAll.revision())
190+
.pipe(gulp.dest(root.tmp))
191+
})
192+
193+
gulp.task('revision:copy', () => {
194+
gulp.src(`${root.tmp}/**/*`)
195+
.pipe(gulp.dest(paths.dist.root))
196+
})

gulpfile.coffee

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)