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

Add preact/compat aliases by default #12403

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 19 additions & 0 deletions app/preact/src/server/framework-preset-preact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import path from 'path';
import { TransformOptions } from '@babel/core';
import { Configuration } from 'webpack'; // eslint-disable-line

export function babelDefault(config: TransformOptions) {
return {
Expand All @@ -9,3 +11,20 @@ export function babelDefault(config: TransformOptions) {
],
};
}

export function webpackFinal(config: Configuration) {
return {
...config,
resolve: {
...config.resolve,
// Prefer top-level aliases
modules: [path.resolve('node_modules'), ...config.resolve.modules],
// Alias react imports to "preact/compat":
alias: {
...config.resolve.alias,
react: require.resolve('preact/compat'),
'react-dom': require.resolve('preact/compat'),
Comment on lines +25 to +26
Copy link
Contributor

@merceyz merceyz Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
react: require.resolve('preact/compat'),
'react-dom': require.resolve('preact/compat'),
react: path.dirname(require.resolve('preact/compat/package.json')),
'react-dom': path.dirname(require.resolve('preact/compat/package.json')),

My bad, needs to get the entry path otherwise node will load from main instead of letting webpack load from module

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing
it creates nice path
but the end result is that ui is stuck
It compiles well, shows storybook controls and then stuck with a loader...

},
},
};
}