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

feat(babel): support for dynamic imports and requires #1330

Merged
merged 2 commits into from
Aug 27, 2023
Merged

Conversation

Anber
Copy link
Collaborator

@Anber Anber commented Aug 24, 2023

Motivation

const url = "./__fixtures__/FOO";
const foo2 = require(url.toLowerCase()).foo2;

Summary

Dependencies missed during the preparation stage can now be handled during evaluation.

@changeset-bot
Copy link

changeset-bot bot commented Aug 24, 2023

🦋 Changeset detected

Latest commit: f8c5d7c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
@linaria/babel-preset Patch
@linaria/testkit Patch
@linaria/cli Patch
@linaria/esbuild Patch
linaria Patch
@linaria/rollup Patch
@linaria/stylelint Patch
@linaria/vite Patch
@linaria/webpack4-loader Patch
@linaria/webpack5-loader Patch
esbuild-example Patch
rollup-example Patch
vite-example Patch
vpssr-linaria-solid-example Patch
@linaria/webpack-loader Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@PierreGUI
Copy link

PierreGUI commented Aug 25, 2023

Tested this branch with my build, it bursts a ton of warnings:

[linaria] ... has a module-resolver plugin in its babelrc, but it is not presentin the babelOptions for the linaria plugin. This works for now but will be an error in the future.Please add the module-resolver plugin to the babelOptions for the linaria plugin.

Note: Adding the plugin to linaria's babelOptions in webpack config doesn't seem to help.

Then, the build stops and node crashes with a FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 🥵

  • Node v16.14.2
  • Mac OSX Ventura 13.4.1

@Anber
Copy link
Collaborator Author

Anber commented Aug 27, 2023

Ok, there are at least three different problems:

  1. The warning should be shown at most once.
  2. It should not be shown if you have module-resolver in babelOptions.
  3. The out-of-memory error. It can be okay if you have a massive code base because the memory usage is far from optimal right now, but if you have something like 100-200 components or even less, and it happens, it may be caused by some endless recursion in processing.

The first two are simple. The third one requires future investigation. First, I'm going to minimise memory usage.

@Anber Anber merged commit 8a5d734 into master Aug 27, 2023
4 checks passed
@Anber Anber deleted the dynamic-require branch August 27, 2023 10:18
@Anber
Copy link
Collaborator Author

Anber commented Aug 27, 2023

Memory-related work will be done here #1331

@PierreGUI
Copy link

Thanks!
FYI the MR fixed the multiple warnings, but I still get one when configuring babelOptions from Webpack:

.babelrc:

"plugins": [["module-resolver", { "alias": { "~": "./src" }}]

webpack.js:

loader: '@linaria/webpack5-loader',
options: {
	babelOptions: {
		plugins: [
			["module-resolver", { "alias": { "~": "./src" }}],
		],
	},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants