Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browserSync integration #17

Closed
danizen opened this issue Mar 29, 2022 · 4 comments
Closed

browserSync integration #17

danizen opened this issue Mar 29, 2022 · 4 comments
Labels
Enhancement New feature or request

Comments

@danizen
Copy link

danizen commented Mar 29, 2022

With #5, I asked a very general question (which was unanswered). Now I am moving to @uswds/compile, and I wonder about something more specific. How can I both utilize the compileSass export and also integrate with browserSync?

I have modified the task "build-sass" from uswds-gulp as follows:

gulp.task("build-sass", function (done) {
  var plugins = [
    // Autoprefix
    autoprefixer({
      cascade: false,
      grid: true,
    }),
    // Minify
    csso({ forceMediaMerge: false }),
  ];
  return (
    gulp
      .src([`${PROJECT_SASS_SRC}/*.scss`])
      .pipe(sourcemaps.init({ largeFile: true }))
      .pipe(
        sass.sync({
          includePaths: [
            `${PROJECT_SASS_SRC}`,
            `${uswds}/scss`,
            `${uswds}/scss/packages`,
          ],
        })
      )
      .pipe(replace(/\buswds @version\b/g, "based on uswds v" + pkg.version))
      .pipe(postcss(plugins))
      .pipe(sourcemaps.write("."))
      // uncomment the next line if necessary for Jekyll to build properly
      //.pipe(gulp.dest(`${SITE_CSS_DEST}`))
      .pipe(gulp.dest(`${CSS_DEST}`))
      .pipe(browserSync.stream())
  );
});
@mejiaj
Copy link
Contributor

mejiaj commented Mar 29, 2022

@danizen sorry, I thought I answered that question you mentioned somewhere else.

My answer was, we'll do security updates where possible, but we won't do active development on uswds-gulp. Users should switch to uswds compile.

For browserSync, the method you mention above works. You could try manual reloading.

For now, I think we're okay leaving it in the hands of the user. If there's enough interest we can take another look at integrating something, maybe a browsersync flag 🤔.

@mejiaj mejiaj added the Enhancement New feature or request label Mar 29, 2022
@danizen
Copy link
Author

danizen commented Mar 29, 2022

@mejiaj ,

Since the method uswds.compileSass returns a Vinyl stream (iterator of vinyl objects), this could be called by my method and piped to browser Sync, but this is a level of integration that forces me to interact very low level.

A better integration method turned out to explicitly monitor the files that my build produces, and then I can define a series that uses the uswds provided tasks:

function initServe(cb) {
  browserSync.init({
    "server": {
      "baseDir": ["./examples", "./dist"],
      "index": "index.htm"
    },
    "files": [
      "./dist/css/nlm-uswds.css",
      "./examples/basic.htm",
      "./examples/alla.htm",
      "./examples/index.htm"
    ]
  });
  cb();
}

exports.serve = gulp.series(uswds.updateUswds, initServe, uswds.watch);

I suggest that the label be changed then from "enhancement" to "documentation" and you might simply add it to the README or some example code. I will ask whether I can make our build public, and if so, put a link to it here.

@danizen
Copy link
Author

danizen commented Mar 29, 2022

Nevermind - this can be changed to documentation or simply closed, whenever.

@mejiaj
Copy link
Contributor

mejiaj commented Mar 29, 2022

Hey @danizen! Thank you for the examples and suggestions.

We've decided to not include this specific example into our docs, but we do want to improve our documentation and code (if needed) to work better with user tasks.

One of the major drivers of creating this package was to improve interoperability with users' own tasks. I've created this issue #18. We'll be using your feedback and other customer feedback to improve our docs. Thanks again!

@mejiaj mejiaj closed this as completed Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants