質問編集履歴
2
jsファイル 追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,4 +22,276 @@
|
|
22
22
|
その後も、cssファイルは更新されない
|
23
23
|
|
24
24
|
#やってみたこと2
|
25
|
-
gulpと実行し、そのままの状態で、sassファイルに修正を加えるとcssファイルの更新日が変わることが確認できました。これは正しい手順でしょうか???
|
25
|
+
gulpと実行し、そのままの状態で、sassファイルに修正を加えるとcssファイルの更新日が変わることが確認できました。これは正しい手順でしょうか???
|
26
|
+
|
27
|
+
■gulpfile.js
|
28
|
+
```js
|
29
|
+
var gulp = require('gulp');
|
30
|
+
var $ = require('gulp-load-plugins')();
|
31
|
+
var browserify = require('browserify');
|
32
|
+
var babelify = require('babelify');
|
33
|
+
var watchify = require('watchify');
|
34
|
+
var source = require('vinyl-source-stream');
|
35
|
+
var runSequence = require('run-sequence');
|
36
|
+
|
37
|
+
var ga2 = {
|
38
|
+
src: './',
|
39
|
+
pub: '../public/',
|
40
|
+
assets: '../public/assets/',
|
41
|
+
js: {
|
42
|
+
src: './js/',
|
43
|
+
pub: '../public/assets/js/'
|
44
|
+
},
|
45
|
+
css: {
|
46
|
+
src: './css/',
|
47
|
+
pub: '../public/assets/css/'
|
48
|
+
},
|
49
|
+
img: {
|
50
|
+
src: './img/',
|
51
|
+
pub: '../public/assets/img/'
|
52
|
+
},
|
53
|
+
html: {
|
54
|
+
src: './html/',
|
55
|
+
pub: '../public/'
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
// scripts
|
60
|
+
gulp.task('watchify:ga2', function(){
|
61
|
+
return compileJs({
|
62
|
+
file: 'main.js',
|
63
|
+
src: ga2.js.src,
|
64
|
+
dest: ga2.js.pub
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
gulp.task('watchify:gaModules', function(){
|
69
|
+
return compileJs({
|
70
|
+
file: 'ga-modules.js',
|
71
|
+
src: ga2.js.src,
|
72
|
+
dest: ga2.js.pub
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
gulp.task('watchify:gaWidgets', function(){
|
77
|
+
return compileJs({
|
78
|
+
file: 'ga-widgets.js',
|
79
|
+
src: ga2.js.src,
|
80
|
+
dest: ga2.js.pub
|
81
|
+
});
|
82
|
+
});
|
83
|
+
|
84
|
+
gulp.task('watchify:gaWidgetsDev', function(){
|
85
|
+
return compileJs({
|
86
|
+
file: 'ga-widgets-dev.js',
|
87
|
+
src: ga2.js.src,
|
88
|
+
dest: ga2.js.pub
|
89
|
+
});
|
90
|
+
});
|
91
|
+
|
92
|
+
function compileJs(opt){
|
93
|
+
var bundler = watchify(browserify({
|
94
|
+
entries: [opt.src + opt.file],
|
95
|
+
transform: ['babelify', 'coffeeify', 'browserify-shim'],
|
96
|
+
cache: {},
|
97
|
+
packageCache: {}
|
98
|
+
}));
|
99
|
+
|
100
|
+
function bundle(){
|
101
|
+
return bundler
|
102
|
+
.bundle()
|
103
|
+
.on('error', handleErrors)
|
104
|
+
.pipe(source(opt.file))
|
105
|
+
.pipe($.duration('compiled ' + opt.file))
|
106
|
+
.pipe(gulp.dest(opt.dest))
|
107
|
+
.pipe($.connect.reload());
|
108
|
+
}
|
109
|
+
|
110
|
+
bundler.on('update', bundle);
|
111
|
+
return bundle();
|
112
|
+
}
|
113
|
+
|
114
|
+
gulp.task('watchify', ['watchify:ga2', 'watchify:gaModules', 'watchify:gaWidgets', 'watchify:gaWidgetsDev']);
|
115
|
+
gulp.task('scripts:modules', function(){
|
116
|
+
return gulp.src(ga2.js.src + 'page-modules/*.js')
|
117
|
+
.pipe(gulp.dest(ga2.js.pub + 'modules/'))
|
118
|
+
.pipe($.connect.reload());
|
119
|
+
});
|
120
|
+
|
121
|
+
// styles
|
122
|
+
gulp.task('styles:ga2', function(){
|
123
|
+
return gulp.src(ga2.css.src + '**/*.{sass,scss}')
|
124
|
+
.pipe($.sass({
|
125
|
+
outputStyle: 'compact'
|
126
|
+
})
|
127
|
+
.on('error', handleErrors))
|
128
|
+
.pipe($.autoprefixer({
|
129
|
+
browsers: ['last 2 versions', 'iOS >= 7', 'Android >= 4', 'Explorer >= 9'],
|
130
|
+
cascade: false
|
131
|
+
}))
|
132
|
+
.pipe(gulp.dest(ga2.css.pub))
|
133
|
+
.pipe($.connect.reload());
|
134
|
+
});
|
135
|
+
|
136
|
+
// html
|
137
|
+
var configJson = require(ga2.html.src + 'config.json');
|
138
|
+
var jadePages = ga2.html.src + 'pages/**/*.jade';
|
139
|
+
var jadeTemplates = ga2.html.src + 'layouts/**/*.jade';
|
140
|
+
|
141
|
+
gulp.task('jade:page', function(){
|
142
|
+
return gulp.src(jadePages)
|
143
|
+
.pipe($.changed(ga2.html.pub, {
|
144
|
+
extension: '.html'
|
145
|
+
}))
|
146
|
+
.pipe($.plumber({
|
147
|
+
errorHandler: handleErrors
|
148
|
+
}))
|
149
|
+
.pipe($.jade({
|
150
|
+
pretty: true,
|
151
|
+
basedir: ga2.html.src,
|
152
|
+
data: configJson
|
153
|
+
}))
|
154
|
+
.pipe(gulp.dest(ga2.html.pub));
|
155
|
+
});
|
156
|
+
|
157
|
+
gulp.task('jade:templates', function(){
|
158
|
+
return gulp.src(jadePages)
|
159
|
+
.pipe($.plumber({
|
160
|
+
errorHandler: handleErrors
|
161
|
+
}))
|
162
|
+
.pipe($.jade({
|
163
|
+
pretty: true,
|
164
|
+
basedir: ga2.html.src,
|
165
|
+
data: configJson
|
166
|
+
}))
|
167
|
+
.pipe(gulp.dest(ga2.html.pub));
|
168
|
+
});
|
169
|
+
|
170
|
+
gulp.task('html', ['jade:page']);
|
171
|
+
gulp.task('html:templates', ['jade:templates']);
|
172
|
+
gulp.task('html:json', function(){
|
173
|
+
return gulp.src(ga2.html.pub + '_api/*.html')
|
174
|
+
.pipe($.htmlToJson())
|
175
|
+
.pipe(gulp.dest(ga2.html.pub + '_api/'));
|
176
|
+
});
|
177
|
+
|
178
|
+
var jsonFiles = [
|
179
|
+
'head-notifier',
|
180
|
+
'ranking-mo',
|
181
|
+
'ga-comment_01',
|
182
|
+
'ga-comment_02',
|
183
|
+
'ga-comment-post_01',
|
184
|
+
'ga-comment-post_02',
|
185
|
+
'pm-lk_comment-01',
|
186
|
+
'pm-lk_comment-02',
|
187
|
+
'pm-tw-list'
|
188
|
+
];
|
189
|
+
|
190
|
+
gulp.task('json:merge', function(){
|
191
|
+
var filename, i, len, results;
|
192
|
+
results = [];
|
193
|
+
for(i = 0, len = jsonFiles.length; i < len; i++){
|
194
|
+
filename = jsonFiles[i];
|
195
|
+
results.push(gulp.src(ga2.html.pub + '_api/' + filename + '*.json')
|
196
|
+
.pipe($.extend(filename + '.json'))
|
197
|
+
.pipe(gulp.dest(ga2.html.pub + '_api/')));
|
198
|
+
}
|
199
|
+
return results;
|
200
|
+
});
|
201
|
+
|
202
|
+
gulp.task('json:api', function(){
|
203
|
+
return runSequence('html:json', 'json:merge');
|
204
|
+
});
|
205
|
+
gulp.task('html', function(){
|
206
|
+
return runSequence('jade:page', 'json:api');
|
207
|
+
});
|
208
|
+
gulp.task('html:templates', function(){
|
209
|
+
return runSequence('jade:templates', 'json:api');
|
210
|
+
});
|
211
|
+
|
212
|
+
// image
|
213
|
+
gulp.task('image:svg', function(){
|
214
|
+
return gulp.src(ga2.img.pub + '**/*.svg')
|
215
|
+
.pipe($.svgmin())
|
216
|
+
.pipe(gulp.dest(ga2.img.pub));
|
217
|
+
});
|
218
|
+
|
219
|
+
// minify
|
220
|
+
gulp.task('minify:scripts', function(){
|
221
|
+
return gulp.src(ga2.assets + '**/*.js')
|
222
|
+
.pipe($.uglify({
|
223
|
+
preserveComments: 'some'
|
224
|
+
}))
|
225
|
+
.pipe(gulp.dest(ga2.assets));
|
226
|
+
});
|
227
|
+
|
228
|
+
gulp.task('minify:styles', function(){
|
229
|
+
return gulp.src(ga2.assets + '**/*.css')
|
230
|
+
.pipe($.cleanCss())
|
231
|
+
.pipe(gulp.dest(ga2.assets));
|
232
|
+
});
|
233
|
+
gulp.task('minify', ['minify:scripts', 'minify:styles']);
|
234
|
+
|
235
|
+
// build
|
236
|
+
gulp.task('browserify:ga2', function(){
|
237
|
+
browserify({
|
238
|
+
entries: ['./js/main.js'],
|
239
|
+
transform: ['babelify', 'coffeeify', 'browserify-shim'],
|
240
|
+
cache: {},
|
241
|
+
packageCache: {}
|
242
|
+
})
|
243
|
+
.bundle()
|
244
|
+
.pipe(source('./js/main.js'))
|
245
|
+
.pipe(gulp.dest('../public/assets/'));
|
246
|
+
});
|
247
|
+
|
248
|
+
gulp.task('browserify:modules', function(){
|
249
|
+
browserify({
|
250
|
+
entries: ['./js/ga-modules.js'],
|
251
|
+
transform: ['babelify', 'coffeeify', 'browserify-shim'],
|
252
|
+
cache: {},
|
253
|
+
packageCache: {}
|
254
|
+
})
|
255
|
+
.bundle()
|
256
|
+
.pipe(source('./js/ga-modules.js'))
|
257
|
+
.pipe(gulp.dest('../public/assets/'));
|
258
|
+
});
|
259
|
+
|
260
|
+
gulp.task('build:js', ['browserify:ga2', 'browserify:modules', 'scripts:modules']);
|
261
|
+
gulp.task('build:sass', ['styles:ga2']);
|
262
|
+
gulp.task('build', ['build:sass', 'build:js']);
|
263
|
+
|
264
|
+
// web server
|
265
|
+
gulp.task('server', function(){
|
266
|
+
$.connect.server({
|
267
|
+
root: ga2.pub,
|
268
|
+
port: 8000,
|
269
|
+
livereload: true
|
270
|
+
});
|
271
|
+
});
|
272
|
+
|
273
|
+
// watch
|
274
|
+
gulp.task('watch', function(){
|
275
|
+
gulp.watch(ga2.js.src + 'page-modules/*.js', { interval: 750 }, ['scripts:modules']);
|
276
|
+
gulp.watch(ga2.css.src + '**/*.{sass,scss}', { interval: 750 }, ['styles:ga2']);
|
277
|
+
gulp.watch(jadePages, { interval: 750 }, ['html']);
|
278
|
+
gulp.watch(jadeTemplates, { interval: 750 }, ['html:templates']);
|
279
|
+
gulp.watch(ga2.html.pub + '_api/*.html', { interval: 750 }, ['json:api']);
|
280
|
+
gulp.watch(ga2.pub + '**/*.html', { interval: 750 }, function(e){
|
281
|
+
return gulp.src(e.path)
|
282
|
+
.pipe($.connect.reload());
|
283
|
+
});
|
284
|
+
});
|
285
|
+
gulp.task('default', ['server', 'watch', 'watchify']);
|
286
|
+
|
287
|
+
// utils
|
288
|
+
var handleErrors = function(){
|
289
|
+
var args = Array.prototype.slice.call(arguments);
|
290
|
+
$.notify.onError({
|
291
|
+
title: 'Task Error',
|
292
|
+
message: '<%= error %>'
|
293
|
+
}).apply(this, args);
|
294
|
+
return this.emit('end');
|
295
|
+
};
|
296
|
+
|
297
|
+
```
|
1
試してみたことを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,7 +16,10 @@
|
|
16
16
|
・gulpコマンドを実行しても、いっこうに終わる気配がないためコントロール+Cでプロンプトにもどらざるをえない
|
17
17
|
・gulpfile.coffeeファイルが見当たらない
|
18
18
|
|
19
|
-
#やってみたこと
|
19
|
+
#やってみたこと1
|
20
20
|
npm uninstall gulp-sass
|
21
21
|
npm install gulp-sass --save-dev
|
22
|
-
その後も、cssファイルは更新されない
|
22
|
+
その後も、cssファイルは更新されない
|
23
|
+
|
24
|
+
#やってみたこと2
|
25
|
+
gulpと実行し、そのままの状態で、sassファイルに修正を加えるとcssファイルの更新日が変わることが確認できました。これは正しい手順でしょうか???
|