Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

109 rader
2.9 KiB

  1. import { src, dest, watch, series, parallel } from 'gulp';
  2. import yargs from 'yargs';
  3. import sass from 'gulp-sass';
  4. import cleanCss from 'gulp-clean-css';
  5. import gulpIf from 'gulp-if';
  6. import postcss from 'gulp-postcss';
  7. import sourcemaps from 'gulp-sourcemaps';
  8. import autoprefixer from 'autoprefixer';
  9. import imagemin from 'gulp-imagemin';
  10. import webpack from 'webpack-stream';
  11. import named from 'vinyl-named';
  12. import fileInclude from 'gulp-file-include'
  13. import del from 'del';
  14. import browserSync from "browser-sync";
  15. const PRODUCTION = yargs.argv.prod;
  16. export const styles = () => {
  17. return src(['source/sass/main.scss', 'source/sass/print.scss'])
  18. .pipe(gulpIf(!PRODUCTION, sourcemaps.init()))
  19. .pipe(sass().on('error', sass.logError))
  20. .pipe(gulpIf(PRODUCTION, postcss([ autoprefixer ])))
  21. .pipe(gulpIf(PRODUCTION, cleanCss({compatibility:'ie11'})))
  22. .pipe(gulpIf(!PRODUCTION, sourcemaps.write()))
  23. .pipe(dest('output/css/styles/inner'));
  24. }
  25. export const scripts = () => {
  26. return src(['source/js/index.js'])
  27. .pipe(named())
  28. .pipe(webpack({
  29. module: {
  30. rules: [
  31. {
  32. test: /\.js$/,
  33. use: {
  34. loader: 'babel-loader',
  35. options: {
  36. presets: []
  37. }
  38. }
  39. },
  40. {
  41. test: /\.css$/,
  42. use: [ 'style-loader', 'css-loader']
  43. },
  44. ]
  45. },
  46. mode: PRODUCTION ? 'production' : 'development',
  47. devtool: /* !PRODUCTION ? 'eval-cheap-source-map' :*/ false,
  48. output: {
  49. filename: '[name].js'
  50. },
  51. }))
  52. .pipe(dest('output/js'));
  53. }
  54. export const images = () => {
  55. src('source/dummy/**/*.{jpg,jpeg,png,svg,gif}')
  56. .pipe(gulpIf(PRODUCTION, imagemin()))
  57. .pipe(dest('output/dummy'));
  58. return src('source/img/**/*.{jpg,jpeg,png,svg,gif}')
  59. .pipe(gulpIf(PRODUCTION, imagemin()))
  60. .pipe(dest('output/img'));
  61. }
  62. export const copy = () => {
  63. src(['source/services/**/*'])
  64. .pipe(dest('output/services/'));
  65. return src(['source/fonts/**/*'])
  66. .pipe(dest('output/fonts/'));
  67. }
  68. export const html = () => {
  69. return src(['./source/pages/*'])
  70. .pipe(fileInclude({
  71. prefix: '@@',
  72. basepath: './source/includes/'
  73. }))
  74. .pipe(dest('./output/'));
  75. }
  76. export const clean = () => del(['output']);
  77. const server = browserSync.create();
  78. export const serve = done => {
  79. server.init({
  80. proxy: "http://localhost/ihk24/templates/output"
  81. });
  82. done();
  83. };
  84. export const reload = done => {
  85. server.reload();
  86. done();
  87. };
  88. export const watcher = () => {
  89. watch('source/sass/**/*.scss', series(styles, reload));
  90. watch(['source/img/**/*.{jpg,jpeg,png,svg,gif}', 'source/dummy/**/*.{jpg,jpeg,png,svg,gif}'], series(images, reload));
  91. watch(['source/fonts/**/*'], series(copy, reload));
  92. watch('source/js/**/*.js', series(scripts, reload));
  93. watch(['source/pages/**/*', 'source/includes/**/*'], series(html, reload));
  94. }
  95. export const dev = series(clean, parallel(html, styles, scripts, images, copy), serve, watcher);
  96. export const build = series(clean, parallel(html, styles, scripts, images, copy));
  97. export default dev;