Git Product home page Git Product logo

dynamic-alias-resolve-plugin's People

Contributors

dependabot[bot] avatar heiseshandian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dynamic-alias-resolve-plugin's Issues

pattern option does not appear to work as explained.

The test pattern used across my webpack config is /\.(js|mjs|jsx|ts|tsx)$/
This leads to the dynamic function never being called.
Using a slight tweak to the example /\.ts$/ also leads to dynamic function never being called.
The repo is full of .ts, .tsx, and .js files.
/.*/ is the only way I've found so far to get the function passed to dynamic getting called.
Tested via a build script with

new DynamicAliasResolvePlugin({
    alias: "lib",
    dynamic: (request, alias) => {
        throw new Error()
    },
    pattern: /.*/,
    // pattern: /\.(js|mjs|jsx|ts|tsx)$/,
})

Request for examples.

Using this setup and it does return absolute paths as desired, however the webpack build fails.

new DynamicAliasResolvePlugin({
    alias: ["lib", "components"],
    dynamic: (request, alias) => {
        console.log({ request })
        let resolvedPath
        if (request.descriptionFileData.name === 'shared') {
            resolvedPath = path.resolve(paths.shared, request.request)
        } else {
            resolvedPath = path.resolve(paths.appSrc, request.request)
        }

        console.log({ resolvedPath })

        return resolvedPath
    },
    pattern: /.*/,
}),

console.log output confirms paths:

{
  request: {
    context: {
      issuer: '/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/utils/cookie/cookieUtils.ts',
      compiler: undefined
    },
    path: '/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/utils/cookie',
    request: 'lib/constants/cookieConstants',
    query: '',
    module: true,
    directory: false,
    file: false,
    descriptionFilePath: '/Users/me/Documents/co/repos/client/workspaces/shared/package.json',
    descriptionFileData: {
      name: 'shared',
      version: '0.1.0',
      private: true,
      type: 'module',
      scripts: [Object],
      browserslist: [Object],
      eslintConfig: [Object],
      jest: [Object]
    },
    descriptionFileRoot: '/Users/me/Documents/co/repos/client/workspaces/shared',
    relativePath: './src/lib/utils/cookie'
  }
}
{
  resolvedPath: '/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/constants/cookieConstants'
}

Yet getting this error:

Failed to compile.

/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/utils/cookie/cookieUtils.ts
Cannot find module: 'lib/constants/cookieConstants'. Make sure this package is installed.

Please provide examples is this isn't the correct way to use this plugin.

Bug report: about index.ts

If someone write import A from @/A, it can be import @/A.ts or @/A/index.ts. Your plugin cannot handle @/A/index.ts case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.