Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. // プラグインの読み込み
  2. var gulp = require("gulp");
  3. var postcssimport = require('postcss-import');
  4. var postcss = require('gulp-postcss'); //gulp-postcssをインポート
  5. var cssnext = require('postcss-cssnext'); //cssnextをインポート
  6. var nested = require('postcss-nested');
  7. var csswring = require('csswring');
  8. var calc = require('postcss-calc');
  9. var customProperties = require("postcss-custom-properties");
  10. var browserSync = require("browser-sync");
  11.  
  12. // style.scssをコンパイルします。
  13. // コンパイル後は、src/cssフォルダにソースマップとともにファイルを保存します。
  14. gulp.task("default", function () {
  15. gulp.src("src/css/style.scss");// 対象の決定
  16. // .pipe(sourcemaps.init())// プラグインの実行
  17. // .pipe(sass({outputStyle: "expanded"}))
  18. // .pipe(autoprefixer({
  19. // browsers: ["ios_saf >= 8", "Android >= 4"]
  20. // }));
  21. return gulp.src(
  22. ['./src-before/' , './src-before//*'],
  23. { base: 'src-before' }) //src-before下にある.cssファイルを指定
  24. .pipe(postcssimport())
  25. .pipe(postcss())
  26. .pipe(cssnext()) //PostCSSにファイルを処理してもらう
  27. .pipe(nested())
  28. .pipe(csswring())
  29. .pipe(calc())
  30. .pipe(browserSync())
  31. .pipe(autoprefixer({
  32. browsers: ["ios_saf >= 8", "Android >= 4"]
  33. }))
  34. .pipe(postcss(plugins))
  35. .pipe(gulp.dest('./dest-after/css')); //生成されたCSSをdest-after下に配置
  36. });
  37.  
  38. //ローカルサーバーを立て、
  39. //ファイル更新時に自動リロードするタスクです
  40. gulp.task("default", function () {
  41. //初期設定です
  42. browserSync.init({
  43. server: {
  44. baseDir: "./" // このディレクトリをルートとしたサーバを立ち上げることができる。
  45. }
  46. });
  47. });
  48.  
  49. gulp.watch ("../src-before/foundation/", function () { // ./*に変更があったら下記のブラウザシンクを更新してくれ
  50. browserSync.reload();
  51. });
  52.  
  53. //以下gulp-watch
  54. gulp.task('watch', function(){
  55. gulp.watch(['src-before/' , 'src-before//' , 'src-before///']);//監視したいファイルの相対パス
  56. });
  57.  
  58. [BS] Access URLs:
  59.  
  60. Local: //localhost:3000
  61. External: //192.168.2.111:3000
  62.  
  63. UI: //localhost:3001
  64.  
  65. UI External: //192.168.2.111:3001
  66.  
  67. [BS] Serving files from: ./
  68. [BS] Watching files...
  69. [BS] File changed: ..src-beforefoundation_base.css
  70. [BS] File changed: ..src-beforefoundation_base.css
  71. [BS] File changed: index.html
  72. [BS] File changed: ..src-beforefoundation_base.css
  73.  
  74. C:.
  75. ├─dest-after
  76. │ ├─css
  77. │ │ ├─foundation
  78. │ │ ├─layout
  79. │ │ └─object
  80. │ │ ├─component
  81. │ │ ├─project
  82. │ │ └─utility
  83. │ ├─html
  84. │ ├─img
  85. │ │ ├─common-img
  86. │ │ └─index
  87. │ ├─js
  88. │ ├─plugin
  89. │ └─web-font
  90. ├─node_modules
  91. │ ├─.bin
  92. │ ├─abbrev
  93. │ ├─accepts
  94. │ │ └─node_modules
  95. │ │ ├─mime-db
  96. │ │ └─mime-types
  97.  
  98. const gulp = require("gulp");
  99. const browserSync = require("browser-sync").create();
  100. const postcss = require('gulp-postcss');
  101. const cssPlugins = [
  102. require('postcss-import'),
  103. require('postcss-cssnext'),
  104. require('postcss-nested'),
  105. require('csswring'),
  106. require('postcss-calc'),
  107. require("postcss-custom-properties"),
  108. ];
  109.  
  110. gulp.task("css", function(){
  111. gulp.src('./src-before/css/**/*.css')
  112. .pipe(postcss(cssPlugins))
  113. .pipe(gulp.dest('./dest-after/'));
  114. });
  115.  
  116. gulp.task('watch', function(){
  117. gulp.watch('./src-before/css/**/*.css', ["css"]);
  118. });
  119.  
  120. gulp.task("server", function(){
  121. browserSync.init({
  122. server: {
  123. baseDir: "./dest-after/",
  124. },
  125. });
  126. gulp.watch(['dest-after/*', 'src-before/**' , 'src-before/**/*' , 'src-before/**/**/*']).on('change', browserSync.reload);
  127. });
  128.  
  129. gulp.task("default", ["watch", "server"]);
  130.  
  131. gulp.watch("./dest/**/*").on('change', browserSync.reload);
  132.  
  133. gulp.watch('./src/css/**/*.css', ["css"]);
  134.  
  135. // gulpfile.js
  136. // src -> dest
  137.  
  138. const gulp = require("gulp");
  139. const browserSync = require("browser-sync").create();
  140. const postcss = require('gulp-postcss');
  141. const cssPlugins = [
  142. require('postcss-import'),
  143. require('postcss-cssnext'),
  144. require('postcss-nested'),
  145. require('csswring'),
  146. require('postcss-calc'),
  147. require("postcss-custom-properties"),
  148. ];
  149.  
  150. gulp.task("css", function(){
  151. gulp.src('./src/css/**/*.css')
  152. .pipe(postcss(cssPlugins))
  153. .pipe(gulp.dest('./dest/'));
  154. });
  155.  
  156. gulp.task('watch', function(){
  157. gulp.watch('./src/css/**/*.css', ["css"]);
  158. });
  159.  
  160. gulp.task("server", function(){
  161. browserSync.init({
  162. server: {
  163. baseDir: "./dest/",
  164. },
  165. });
  166. gulp.watch("./dest/**/*").on('change', browserSync.reload);
  167. });
  168.  
  169. gulp.task("default", ["watch", "server"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement