使用Docker进行Gulp Watch任务有什么问题?

时间:2019-12-19 08:19:17

标签: django docker sass gulp

编辑:Gulp“监视”在带有mounted volumes的Windows上不起作用,因为没有发送“文件更改”事件。我当前的解决方案是在我的本地计算机上运行Docker Windows Volume Watcher,同时查看是否可以将this solution集成到我的代码中。

我正在尝试在dockerfile中运行gulp监视任务,并且在更改文件时gulp无法捕获。

快速笔记:

  • 当我将其用于本地托管的wordpress安装时,此设置将起作用
  • 根据pycharm的docker服务,文件更改反映在我的docker容器中
  • 运行“样式” gulp任务有效,只是看文件不起作用

对我来说很明显,gulp如何监视更改与Docker如何做到这一点之间存在某种脱节。

Github link

**编辑:看来可以做我想做的事,here's a link to someone doing it slightly differently.

gulpfile excerpt

#if lib_ver > 20000
#typedef struct x_aaa libaaa
#else
#typedef struct aaa libaaa
#endif

// in your code use `libaaa` instead of `struct aaa`
//struct aaa foo;
libaaa foo;
//struct x_aaa bar;
libaaa bar;

Docker-Compose:

export const watchForChanges = () => {

  watch('scss-js/scss/**/*.scss', gulp.series('styles'));
  watch('scss-js/js/**/*.js', scripts);
  watch('scss-js/scss/*.scss', gulp.series('styles'));
  watch('scss-js/js/*.js', scripts);
  // Try absolute path to see if it works
  watch('scss-js/scss/bundle.scss', gulp.series('styles'));
}
...
// Compile SCSS through styles command
export const styles = () => {
    // Want more than one SCSS file? Just turn the below string into an array
  return src('scss-js/scss/bundle.scss')
      // If we're in dev, init sourcemaps. Any plugins below need to be compatible with sourcemaps.
    .pipe(gulpif(!PRODUCTION, sourcemaps.init()))
      // Throw errors
    .pipe(sass().on('error', sass.logError))
      // In production use auto-prefixer, fix general grid and flex issues.
    .pipe(
      gulpif(
        PRODUCTION,
        postcss([
          autoprefixer({
            grid: true
          }),
          require("postcss-flexbugs-fixes"),
          require("postcss-preset-env")
        ])
      )
    )
    .pipe(gulpif(PRODUCTION, cleanCss({compatibility:'ie8'})))
      // In dev write source maps
    .pipe(gulpif(!PRODUCTION, sourcemaps.write()))
      // TODO: Update this source folder
    .pipe(dest('blog/static/blog/'))
    .pipe(server.stream());
}
...
export const dev = series(parallel(styles, scripts), watchForChanges);

Dockerfile:

version: "3.7"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8002:8000"
      - "3001:3001"
      - "3000:3000"
    volumes:
      - ./django_project:/django_project
    command: >
      sh -c "python manage.py runserver 0.0.0.0:8000"
    restart: always
    depends_on:
      - db
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: example1
    ports:
      - "5432:5432"
    restart: always

您认为可能会发生什么?

1 个答案:

答案 0 :(得分:0)

我的猜测是您正在Windows上运行,对吗?

如果是这样,请看以下答案

https://stackoverflow.com/a/58969398/12153397

链接答案的要旨


问题已识别

绑定安装实际上不适用于docker工具箱:

  主机的已安装文件夹中的

文件更改事件不会传播到   Docker for Windows的容器

解决方案

此脚本旨在解决此问题:docker-windows-volume-watcher