Skip to content

Commit

Permalink
Merge pull request #4 from maksimsemenov/respect-alias-in-user-config f…
Browse files Browse the repository at this point in the history
…ixes #3

Resolve user alias config
  • Loading branch information
amoutonbrady authored Mar 5, 2021
2 parents f1a33de + cb869a5 commit 30e0442
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ 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).map(
(find) => ({
find,
replacement: userAlias[find],
}),
[],
)
: [];

const alias =
command === 'serve' && replaceDev
? [{ find: /^solid-js$/, replacement: 'solid-js/dev' }]
Expand All @@ -36,7 +51,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 30e0442

Please sign in to comment.