jlouns / gulp-requirejs-optimize

Wrapper for the requirejs optimizer for use in gulp
MIT License
62 stars 9 forks source link

build not recognizing paths correctly #28

Open mix3d opened 7 years ago

mix3d commented 7 years ago

I could be setting this up wrong, but here is my issue:

I am noticing in the error log that it is looking for a file that doesn't exist. Error: Error: ENOENT: no such file or directory, open 'path/to/project/assets/js/marionette.js'

In my main.js, I have Marionnette defined as such:

require.config({
    baseURL:'assets/js',
    paths:{
        ...
        marionette  : "vendor/backbone.marionette",
        ...
   }
   shim: {
        ...
        backbone: {
            deps: ['jquery', 'underscore'],
            exports: 'Backbone',
        },
        marionette: {
            deps: ['backbone'],
            exports: 'Marionette',
        },
        ...
    }
});

I looks like the plugin is skipping the config completely (the file should be backbone.marionette.js), since it is not looking in the /vendor/ folder nor is it looking for the right file name.

Here is my simple gulp task:

gulp.task('rqs', function () {
  return gulp.src('assets/js/main.js')
    .pipe(requirejsOptimize(function (file) {
      return {
        siteRoot: '../../',
      };
    }))
  .pipe(gulp.dest('dist'));
});

Am I doing something wrong? Thanks!

jlouns commented 7 years ago

Looks like the issue is that the optimizer isn't getting sent the mainConfigFile parameter that points to your main.js file with the paths config in it. Without that parameter, the optimizer doesn't read the config from the file it's processing, it just uses whatever config you pass to the plugin. Right now, that's just your siteRoot config. I think the task should look something like this:

gulp.task('rqs', function () {
  return gulp.src('assets/js/main.js')
    .pipe(requirejsOptimize({
      mainConfigFile: 'assets/js/main.js'
    }))
  .pipe(gulp.dest('dist'));
});