How should I configure grunt-usemin to work with relative path

前端 未结 9 1635
予麋鹿
予麋鹿 2021-01-30 23:13

I have a grunt project backed by a yeoman-generator that I\'ve built based on the generator-webapp, if it\'s of any help, you can find it on GitHub

The grunt project mak

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 00:11

    My solution was to manually modify grunt-usemin plugin.

    Open node_modules/grunt-usemin/fileprocessor.js in you favourite text editor. Somewhere around line 152 find:

    if (assetSearchPath && assetSearchPath.length !== 0) {
      this.file.searchPath = assetSearchPath;
    }
    

    and replace it with:

    if (assetSearchPath && assetSearchPath.length !== 0) {
      this.file.searchPath.splice(0, 0, assetSearchPath);
    }
    

    By default this.file.searchPath is an array containing the absolute path to the current file. There's no point in overwriting it with ['dist'], it's better to prepend the array with 'dist'. This way if an item is not found in 'dist' directory it might be concluded that either the path is relative or it's wrong. Thus we use the second value from the searchPath array to look for the file and if it was a relative path - we get what we wanted.

提交回复
热议问题