Comments (8)
babel-plugin-wildcard is very close, but doesn't handle the import *
part like we want. I'm going to extract the bits of it that we need so we have our own version that works for us.
from redwood.
@mojombo If you're in a research
phase also check out my old PR for auto importing pages: https://github.com/redwoodjs/redwood/pull/22/files
It added require.context
to nodejs apps that webpack added to apps that they build.
const pages = require.context(path, true, regExp)
I would love to have a standard interface for importing modules in directories across the webpack and nodejs environments, but I don't particularly care what that interface looks like.
from redwood.
@peterp Ok, I looked at that but didn't think it was going to solve the problem; will it indeed result in static import declarations for each file it matches in the dir?
from redwood.
@peterp I don't understand how this will get us what we need for Zip It And Ship It. In Webpack, require.context
will cause the matched modules to be included in the pack, but ZIASI won't know anything about babel-plugin-require-context-hook
and all I get out of it are the filenames of the matched modules, which would then have to be imported with a dynamic import, which ZIASI isn't going to be able to traverse. Unless I'm misunderstanding something.
from redwood.
@mojombo You're right. It is me who has misunderstood.
I was not considering this from the perspective of transpiling dynamic imports into static ones during build time, but instead wanted to provide a common interface to developers wanting to dynamically import things.
I assumed converting dynamic imports into static ones to be something that could be dealt with during packaging or build time for production.
require.context
gives you:
- a function that gives you the results from your search
const req = require.context('./graphql')
req.keys() // ['posts.sdl.js', 'authors.sdl.js']
- And the ability to import them:
req('posts.sdl.js') // the JS module
So the problem in my mind is two fold:
We want a standard programtic interface for dyanmic search based imports in nodejs... A standard does not exist, but webpack does have require.context.
And then:
ZiSi looks at our transpiled source code and tried to determine which modules to include per serverless function, but it ignores dynamic imports. So our transpiled code needs to convert dynamic imports into static ones, or ZiSi needs to understand dynamic imports.
Written on my phone, sorry for mistakes.
from redwood.
Maybe a common interface between environments shouldn't be a concern, in which case this babel macro looks great: https://github.com/kentcdodds/import-all.macro
from redwood.
Let me go up a conceptual level here and explore something before we get into the nitty-gritty of directory imports.
If I'm reading the Netlify docs correctly, it sounds like if you want to deliver unbundled functions code, you can do it (via ZiSi), but it means abandoning the CI system built in to Netlify and you have to manually deploy. Is that true? If so, that's a lot to give up, and I think a discussion is relevant about whether we should be using Webpack on the api side as well, in order to produce a single file deliverable compatible with Netlify CI.
In that world, we could just use normal require.context
from Webpack and be done with it.
from redwood.
Closed by redwoodjs/create-redwood-app#16
from redwood.
Related Issues (20)
- [RFC]: Omit front side - use Redwoodjs as a Server only HOT 3
- [Bug?]: dbAuth handler resePasword does not validate password format as signup does HOT 4
- [RFC]: FieldError not being populated with server errors when inside Controller when using custom UI components HOT 5
- [Bug?]: graphiql authImpersonation breaking on windows HOT 3
- [Bug?]: Flight control deployment not working HOT 2
- [Bug?]: yarn scaffold script shows 404 when fetching packages HOT 9
- [Bug]: CLI commands fail due to unawaited promise (JS projects)
- [Bug?]: baremetal production HOT 5
- [Bug?]: MockGraphQLQuery not working when original query uses fragments HOT 10
- [Bug] Doubled up title when no explicit <title> set
- [Docs]: Outdated / incomplete doc regarding async directive testing HOT 3
- [Bug?]: Upgrading Redwood to Canary causes "unmountComponentAtNode is not a function" in Storybook
- [Bug?]: When using Trusted Documents and Auth, the Current User query is not permitted preventing authentication to work properly
- [Bug?]: `yarn rw dev` doesn't work because of fsevents dep HOT 7
- chore(deps): update dependency @supabase/supabase-js to v2.43.5
- [Bug?]: Can't configure Jest/Vitest to run tests inside of scripts dir
- [Bug?]: `web/src/auto-imports.d.ts` file generated after running `yarn rw storybook-vite` HOT 4
- [Bug?]: Pre-render does not work HOT 7
- [Bug?]: Flaky Testing with Prisma migrations failing HOT 5
- [Bug]: Docs search is broken HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redwood.