Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve user alias config #4

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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