Giter Site home page Giter Site logo

Comments (8)

mojombo avatar mojombo commented on July 30, 2024

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.

peterp avatar peterp commented on July 30, 2024

@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.

mojombo avatar mojombo commented on July 30, 2024

@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.

mojombo avatar mojombo commented on July 30, 2024

@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.

peterp avatar peterp commented on July 30, 2024

@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:

  1. a function that gives you the results from your search
const req = require.context('./graphql')
req.keys() // ['posts.sdl.js', 'authors.sdl.js']
  1. 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.

peterp avatar peterp commented on July 30, 2024

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.

mojombo avatar mojombo commented on July 30, 2024

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.

mojombo avatar mojombo commented on July 30, 2024

Closed by redwoodjs/create-redwood-app#16

from redwood.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.