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

scripts.js not loading #6

Open
d8nieldonaldson opened this issue Oct 31, 2017 · 2 comments
Open

scripts.js not loading #6

d8nieldonaldson opened this issue Oct 31, 2017 · 2 comments

Comments

@d8nieldonaldson
Copy link

Thanks for making this, it is very nice.
I have encountered 1 prob, though, which follows.

steps:

  1. clone repo
  2. npm install
  3. gulp
  4. get error in browser "Failed to load resource: the server responded with a status of 404 (Not Found)" script.js

Any ideas?

Thanks!

@AaronBP
Copy link

AaronBP commented Dec 12, 2017

In index.pug script file is being loaded as if it is already in public/js folder but there doesn't seem to be a gulp task to move the js file into this folder automatically. I'll be looking getting this to working this week, so I will post my solution :)

@AaronBP
Copy link

AaronBP commented Apr 19, 2018

I know, I know. It's been a while! But here it is...

In gulpfile.js

  1. In paths obj, add this entry:
    js: './public/js/'

  2. Add a gulp task for JS using the path we just made.

gulp.task('js', function () {
  return gulp.src('./src/js/**/*.js')
      .pipe(gulp.dest(paths.js))
});
  1. In the existing gulp ‘rebuild’ task add the js task just created
gulp.task('rebuild', ['pug', **'js'**], function () { 
….
)};

  1. In the gulp ‘watch’ task, add:
    gulp.watch('./src/**/*.js', ['rebuild']);
    This watches the js files for changes, and then fires the rebuild task we updated a second ago.

Now, adding something like this to src/js/scripts.js should result in an output in the browser.

console.log('<3 js');

Make sure to re-run gulp so that it picks up the changes we made to gulpfile.js

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

No branches or pull requests

2 participants