Skip to content

removeFile plugin API for allowing plugins to participate in removeCombined #344

Open

Description

@jrburke

Suggested by @peol in requirejs/text#33: allow plugins, like the text plugin, to remove resources that are part of a build.

Maybe add a new build API a plugin can implement to do this. First thought:

removeFile(pluginId, resourceId, remove) where:

  • pluginId: String. Plugin ID
  • resourceId: The normalized resource ID
  • remove: Function. Pass it a string of a file name to remove.

Not sure if this is enough. For instance, a require.toUrl maybe useful?

It should be called when removeCombined is in effect, and it would need docs on the plugins.html page.

Activity

  1. added a commit that references this issue on Jun 2, 2013
  2. spalger commented on Sep 20, 2013

    @spalger

    I personally don't see why each plugin would need to implement the removal logic separately. I think it would be simpler if new property functions were included on write, maybe:

    • write.fileContents(filePath|filePath[], contents)
    • write.fileContentsAsModule(filePath|filePath[], moduleName, contents)

    Then when r.js is wrapping up it's optimizations it can unlink all the filesPaths it received following the same logic it uses for removing combined scripts. From the plugin author's perspective it wouldn't require too many changes. In the context of the text plugin it could look something like this:

    finishLoad: function (name, url, strip, content, onLoad) {
      ...
      buildMap[name] = {
        filename: url,
        content: content
      };
      ...
    },
    ...
    write: function (pluginName, moduleName, write, config) {
      ...
      write.fileContentsAsModule(
        buildMap[name].filename,
        pluginName + "!" + moduleName,
        "define(function () { return '" +
          content +
        "';});\n"
      );
      ...
    }

    It might even make sense to just add filePath as an optional argument to write and it's siblings...

    Based on feedback I'd be happy to work this into a pull request. Disclaimer, I am not _at all_ familiar with the magic which occurs inside r.js, but I do ❤️ it.

  3. jrburke commented on Sep 23, 2013

    @jrburke
    MemberAuthor

    The problem is that plugin dependency IDs are opaque to the loader -- it does not try to interpret what they mean. For a given dependency ID like 'pluginId!something-here', the 'something-here' part could be anything, a pointer to a more than one file, in the case of a 'has!some-test?ok.html:notok.html' case, or not even a file, like something that waits for an onload event from an img tag.

  4. spalger commented on Sep 25, 2013

    @spalger

    This API would only be used for plugins that do resolve to file(s) and would just be a simple way for them to declare that "I included this file so it can be deleted if that's what the user wants".

  5. modified the milestones: 2.2.0, 3.0 on Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions