grunt-includes icon indicating copy to clipboard operation
grunt-includes copied to clipboard

Import File From Same Directory

Open steenbag opened this issue 7 years ago • 0 comments

Hi, I have a fairly complex application structure that makes extensive use of the includes functionality. We recently upgraded from ~0.4 to ~1.1 as part of a larger overall build process upgrade. The file structure is:

- app/
-     assets/
-         scripts/
-             ...
-             tasks/
-                 widgets/
-                     _ctrl.js
-                     _fetch-data-service.js
-                     _filter-component.js
-                     module.js

Inside module.js:

    // @import "_ctrl"
    // @import "_fetch-data-service"
    // @import "_filter-component"

Grunt Task config:

includes: {
      build: {
        options: {
          includeRegexp: /\/\/\s*@import\s+['"]?([^'"]+)['"]?\s*$/,
          filenameSuffix: '.js',
          duplicates: false,
          includePath: ['<%= dirs.src %>/scripts/', '<%= dirs.vendor %>']
        },
        cwd: '<%= dirs.src %>/scripts/',
        src: ['\*.js', '\*/\*.js', '**/*.js'],
        filter: function (filepath) {
          var path = require('path'), basename = path.basename(filepath);
          // Exclude anything in the app/assets/scripts/lib directory.
          return filepath.indexOf('lib/') !== 19
              // Only include resources that are files.
            && grunt.file.isFile(filepath)
              // Exclude any filenames beginning with an underscore (reserved for includes).
            && basename.indexOf('_') !== 0;
        },
        dest: '<%= dirs.temp %>/scripts/'
      }
}

When I run Grunt, I get the error Warning: Included file "app/assets/vendor/_ctrl.js" not found. Use --force to continue. when module.js is processed. It appears as though the import plugin is ignoring the current directory (where the requested includes are) when an array is used for options.includePath. I think it would be better behavior to first search the current directory before searching to options.includePaths.

steenbag avatar May 23 '18 14:05 steenbag