Skip to content

Commit

Permalink
Resolve user alias config
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Semenov authored and Maksim Semenov committed Feb 26, 2021
1 parent 39f45fd commit d775f6c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
name: 'solid',
enforce: 'pre',

config(_, { command }) {
config(userConfig, { command }) {
const replaceDev = options.dev !== false;

// Our config will be merged with the user config. However, if user used an object
// format to set aliases, then vite will not be able to properly merge our alias config with the
// user's one.
// To fix that we convert user alias config to array.
const userAlias = userConfig.resolve && userConfig.resolve.alias;
const userAliasArray = !Array.isArray(userAlias)
? Object.keys(userAlias).reduce((accum, aliasKey) => {
accum.push({ find: aliasKey, replacement: userAlias[aliasKey] });
return accum;
}, [])
: [];

const alias =
command === 'serve' && replaceDev
? [{ find: /^solid-js$/, replacement: 'solid-js/dev' }]
Expand All @@ -36,7 +48,11 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
resolve: {
conditions: ['solid'],
dedupe: ['solid-js', 'solid-js/web'],
alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }, ...alias],
alias: [
...userAliasArray,
{ find: /^solid-refresh$/, replacement: runtimePublicPath },
...alias,
],
},
optimizeDeps: {
include: ['solid-js/dev', 'solid-js/web'],
Expand Down

0 comments on commit d775f6c

Please sign in to comment.