2.0.17 • Published 5 years ago

@caviar/next-resolve-alias-plugin v2.0.17

Weekly downloads
31
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage

@caviar/next-resolve-alias-plugin

@caviar/next-block plugin to define module resolving aliases for both server side and client side

Install

$ npm i @caviar/next-resolve-alias-plugin

Usage

caviar.config.js

const AliasPlugin = require('@caviar/next-resolve-alias-plugin')

module.exports = {
  caviar: {
    plugins: [
      new AliasPlugin([{
        id: 'fetch',
        server: 'node-fetch',
        client: 'fetch-ponyfill'
      }], __dirname),
      ...
    ]
  },
  ...
}

The code above will set webpack.output.resolve.alias.fetch as

  • 'node-fetch' in server side
  • and 'fetch-ponyfill' in client side

new AliasPlugin(aliases, defaultFrom?)

  • aliases Array<Alias | string>
  • defaultFrom? path
interface Alias {
  // Module id
  id: string
  // `server` could be
  // - a module id string
  // - a `require.resolve()`d absolute path for a module id
  // - false to prevent from setting resolve alias for server side
  server?: string = id | false
  client?: string = id | false
  // Where should `server` and `client` be resolved from, defaults to `defaultFrom`,
  // will be useless if `server` and `client` are both absolute paths
  from?: string = defaultFrom
}

Using react installed in current project

new AliasPlugin(['react'], __dirname)

Or

// You could resolve the module id yourself
new AliasPlugin([{
  id: 'react',
  server: require.resolve('react'),
  client: require.resolve('react')
}])

// `defaultFrom` could be omitted if `server` and `client` are absolute paths

License

MIT

2.0.17

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago