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

Subfolder in the project - using nude #460

Open
CesarDenis opened this issue Feb 17, 2016 · 22 comments
Open

Subfolder in the project - using nude #460

CesarDenis opened this issue Feb 17, 2016 · 22 comments
Labels

Comments

@CesarDenis
Copy link
Contributor

I need a little help 😊

In my project I need the following file structure:

webapp
└── app
    β”œβ”€β”€ index.html
    β”œβ”€β”€ accessible
    β”‚Β Β  β”œβ”€β”€ index.html
    β”œβ”€β”€ includes
    β”‚Β Β  β”œβ”€β”€ footer.html
    β”‚Β Β  └── header.html
    └── layouts
        └── default.html

When I run the command gulp serve, it works.
But when I run gulp, the folder accessible is not created.

Can someone help me?

Best regards. πŸ˜„

@silvenon
Copy link
Member

Depends on your templating configuration, I'm not sure what you're using. You could try changing this in html task:

return gulp.src('app/*.html')

to this:

return gulp.src(['app/*.html', 'app/accessible/*.html'])

or to include all HTML files except those in includes and layouts:

return gulp.src([
  'app/**/*.html',
  '!app/includes/**/*.html',
  '!app/layouts/**/*.html'
])

@CesarDenis
Copy link
Contributor Author

My html task:

return gulp.src(['app/*.html', '.tmp/*.html'])

then I change:

return gulp.src([
      'app/**/*.html',
      '.tmp/**/*.html',
      '!.tmp/includes/**/*.html',
      '!.tmp/layouts/**/*.html',
      '!app/includes/**/*.html',
      '!app/layouts/**/*.html'
    ])

That's right, or have a simpler way to do?

@CesarDenis
Copy link
Contributor Author

Hi @silvenon, I changed the gulpfile.babel.js , and now with the following error:

events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: Error: File not found with singular glob: /Users/macweb01/Sites/ccr/ras/styles/main.css
    at DestroyableTransform.<anonymous> (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/lib/streamManager.js:90:36)
    at emitOne (events.js:95:20)
    at DestroyableTransform.emit (events.js:182:7)
    at emitOne (events.js:90:13)
    at DestroyableTransform.emit (events.js:182:7)
    at Glob.<anonymous> (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/index.js:38:16)
    at Glob.g (events.js:273:16)
    at emitOne (events.js:90:13)
    at Glob.emit (events.js:182:7)
    at Glob._finish (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:172:8)
    at done (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:159:12)
    at Glob._processSimple2 (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:652:12)
    at /Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:640:10
    at Glob._stat2 (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:736:12)
    at lstatcb_ (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:728:12)
    at RES (/Users/macweb01/Sites/ccr/ras/node_modules/inflight/inflight.js:23:14)

@lukakemperle
Copy link

Same problem here: no browser refresh for .html in subfolders, even with app/**/*.html.

@silvenon
Copy link
Member

@CesarDenis could you share the whole gulpfile.babel.js? It will be much easier to help once I see what templating solution is used.

@artoric

 gulp.watch([
-  'app/*.html',
+  'app/**/*.html',
   'app/images/**/*',
   '.tmp/fonts/**/*'
 ]).on('change', reload);

However, some paths might break in nested HTML files, you should probably start convert them to / paths.

@CesarDenis
Copy link
Contributor Author

@silvenon see my gulpfile.babel.js

It seems that the error is in the plugin useref in task html

@silvenon
Copy link
Member

@CesarDenis only watch .tmp/**/*.html for reloading in the serve task, not app/**/*.html as well. You want the browser to refresh once the Nunjucks templates have already been compiled. Also, you put .tmp/*.html instead of .tmp/**/*.html, the former goes only one level deep.

@silvenon
Copy link
Member

  gulp.watch([
    '.tmp/**/*.html',
    '.tmp/scripts/**/*.js',
    'app/images/**/*',
    '.tmp/fonts/**/*'
  ]).on('change', reload);

@CesarDenis
Copy link
Contributor Author

@silvenon, the error is in default task. Where it generates the final files.

When the html task will generate the subfolder files it displays error:

[09:15:08] Finished 'views' after 10 s
[09:15:08] Starting 'html'...
events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: Error: File not found with singular glob: /Users/macweb01/Sites/ccr/ras/styles/main.css
    at DestroyableTransform.<anonymous> (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/lib/streamManager.js:90:36)
    at emitOne (events.js:95:20)
    at DestroyableTransform.emit (events.js:182:7)
    at emitOne (events.js:90:13)
    at DestroyableTransform.emit (events.js:182:7)
    at Glob.<anonymous> (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/index.js:38:16)
    at Glob.g (events.js:273:16)
    at emitOne (events.js:90:13)
    at Glob.emit (events.js:182:7)
    at Glob._finish (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:172:8)
    at done (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:159:12)
    at Glob._processSimple2 (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:652:12)
    at /Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:640:10
    at Glob._stat2 (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:736:12)
    at lstatcb_ (/Users/macweb01/Sites/ccr/ras/node_modules/gulp-useref/node_modules/glob-stream/node_modules/glob/glob.js:728:12)
    at RES (/Users/macweb01/Sites/ccr/ras/node_modules/inflight/inflight.js:23:14)

It seems that the error is in the plugin useref.

    .pipe($.useref({searchPath: ['.tmp', 'app', '.']}))

To be able to generate the files necessary to change the layout:

This:

<!-- build:css ../styles/main.css -->
<link rel="stylesheet" href="../styles/main.css">
<!-- endbuild -->

For this:

<!-- build:css ../styles/main.css -->
<link rel="stylesheet" href="/app/styles/main.css">
<!-- endbuild -->

@rizqinizamil
Copy link

I also have same problem. Do you have any solution regarding useref error for it?

@silvenon silvenon reopened this Nov 14, 2016
@rizqinizamil
Copy link

This change worked for me;

return gulp.src(['app/*.html', '.tmp/*.html', '.tmp/**/*.html'])
    .pipe($.useref({searchPath: ['.tmp', 'app', '.', '']}))

I use Jade btw.

@neilhem
Copy link
Collaborator

neilhem commented Nov 15, 2016

@rizqinizamil you can shorten code a little bit:

return gulp.src(['app/*.html', '.tmp/**/*.html'])
    .pipe($.useref({searchPath: ['.tmp', 'app', '.', '']}))

@rizqinizamil
Copy link

@neilhem Yes, you are right. Thank you!

@rizqinizamil
Copy link

rizqinizamil commented Nov 16, 2016

Actually I still have a problem. gulp html works for now, but gulp serve works with 404 error on css/js assets, because I set the url into this;

// build:css ../styles/main.min.css
 link(rel='stylesheet' href='app/styles/main.css')
// endbuild

gulp serve works fine when I change it into

// build:css ../styles/main.min.css
 link(rel='stylesheet' href='../styles/main.css')
// endbuild

but got error File not found with singular glob: when I run gulp html.

Any idea?

@silvenon
Copy link
Member

@rizqinizamil what is the difference between those two code blocks?

@rizqinizamil
Copy link

@silvenon Oops, sorry, my fault. I write it with sleepy eyes :|. Please check, I just edited it.

@silvenon silvenon added the bug label Nov 16, 2016
@silvenon
Copy link
Member

silvenon commented Nov 16, 2016

Ok, this seems to be a tricky problem. Correct me if I'm wrong, but the way I understand it is that if you have files at different directory levels extending the same layout with the same useref blocks, assets won't be served/built correctly because they are relative to the HTML files, which exist on different levels.

Right?

@rizqinizamil
Copy link

@silvenon Yes, you are right.

@silvenon
Copy link
Member

This generator is meant more for single page apps, that's why it doesn't support nesting like this. I'll see what I can do, but it will take me some time. If you want, you can create a demo repo with this use case and link it here (let's use Nunjucks), so we can open PRs with our proposed solutions.

@savellem
Copy link

I added mine with the following.

Added this just below the extras script in the gulp file

gulp.task('copy', () => { return gulp.src(['app/**/*']).pipe(gulp.dest('dist')); })

Then changed this guy to add my copy script

gulp.task('build', ['lint', 'html', 'images', 'fonts', 'extras', 'copy'], () => { return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true})); });

Then I made sure all the directories in my subdirectory html linkage is correct and it seems to work for now.

@dainbrain
Copy link

dainbrain commented Apr 30, 2017

[EDIT] I'm dumb and didn't realize the build comments in html actually mattered. Here's how I got my subfolders to work in a basic webapp + nunjucks setup

I followed the steps in the Nunjucks recipe linked from generator-webapp.

I've done all the changes listed in that recipe first, and then I decided to try using subdirectories.

Here's what I did in my gulpfile.js that's different from the recipe:

  1. In my views task include all .njk files but exclude app/layouts and app/includes.
return gulp.src(['app/**/*.njk','!app/includes/**/*.njk','!app/layouts/**/*.njk'])
  1. In my html task do the same, also including/excluding the .tmp directory based on @CesarDenis and @silvenon comments above.
return gulp.src([
      'app/**/*.html',
      '.tmp/**/*.html',
      '!.tmp/includes/**/*.html',
      '!.tmp/layouts/**/*.html',
      '!app/includes/**/*.html',
      '!app/layouts/**/*.html'
    ])
  1. It seemed to work, but the paths for the css/js were still relative, so I changing link paths in the default template for all the links including the build comments. (example):
<!-- build:css /styles/main.css -->
    <link rel="stylesheet" href="/styles/main.css">
<!-- endbuild -->

Now I can create additional child pages in subdirectories like @CesarDenis had in his first comment.

gulp works
gulp serve works
gulp build works
gulp serve:dist works

Thanks for the help in this thread!

@illycz
Copy link
Contributor

illycz commented Sep 22, 2017

@dainbrain but your solution will not work if you need push your code to subfolder, am I right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants