Skip to content
This repository was archived by the owner on Jan 16, 2018. It is now read-only.
This repository was archived by the owner on Jan 16, 2018. It is now read-only.

Add support for aliases regex matching #2

Open

Description

@gunta

Hi again!
I hope to not be too spammy, but I'll try to report all the issues I find along the way ;)

Right now I'm using an alias to resolve a package name,
but the test regex doesn't tries to match the defined aliases.

Current way of doing it:

 resolve: {
      alias: {
        angular: 'angular/angular'
      }
    },
    module: {
      loaders: [{ test: /angular\/angular/, loader: 'exports?angular'}]
    }

Easier and less verbose way supporting alias names:

    module: {
      loaders: [{ test: /^angular$/, loader: 'exports?angular'}]
    }

Or even better, defaulting a test: String parameter to alias matching:

    module: {
      loaders: [{ test: 'angular', loader: 'exports?angular'}]
    }

What do you think?

Activity

  1. sokra commented on Feb 13, 2014

    @sokra
    Member

    Currently loaders are matched against the resolved resource.

    So you could write it less verbose with:

        module: {
          loaders: [{ test: require.resolve('angular/angular'), loader: 'exports?angular'}]
        }

    It may be possible to match against the resolved and non-resolved resource...

  2. gunta commented on Feb 14, 2014

    @gunta
    ContributorAuthor

    I see.

    Some questions:

    1. While require.resolve works for npm packages, how would you resolve it easily for bower packages? Maybe by creating a resolve.anything() function?
    2. I think that test should match resolved, non-resolved, and aliases by default, what do you think?

    If the syntax becomes messy, perhaps using different keys? Something like:

    For aliases:

    module: {
        loaders: [{ testAlias: 'angular', loader: 'exports?angular'}]
    }

    For non-resolved resources:

    module: {
        loaders: [{ testBefore: 'angular', loader: 'exports?angular'}]
    }

    However I think something more simple like being based on the parameter type like this can be easier to use:

    For resolved resources, a Regex pattern:

    module: {
        loaders: [{ test: /angular\.js/, loader: 'exports?angular'}]
    }

    For non-resolved resources and aliases, a plain String:

    module: {
        loaders: [{ test: 'angular', loader: 'exports?angular'}]
    }

    What do you think?

  3. sokra commented on Feb 14, 2014

    @sokra
    Member
    1. require.resolve also works for bower packages if you confiugure the resolving in your configuration to resolve them.
    2. I like the syntax which uses an alternative key for non-resolved matching. i. e. testBefore or testRaw

    strings already have a function. They match the start of the request, so you can pass an absolute path here.

  4. sokra commented on Feb 14, 2014

    @sokra
    Member

    Oh I missunderstood part 1.

    require.resolve in the configuration only resolve npm modules. For other packages you can pass an absolute path to the package. path.join(__dirname, "bower_modules", "myPackage") or write your own resolve function which does this for you (better readable).

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

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions