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 loader for create react app #33

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft

add loader for create react app #33

wants to merge 4 commits into from

Conversation

rykener
Copy link
Owner

@rykener rykener commented Dec 30, 2020

No description provided.

@rykener
Copy link
Owner Author

rykener commented Dec 31, 2020

While in development mode, CRA does not output source files. This prevents django from being able to pickup those files while running npm run start. In order to present Django Manifest Loader as a legitimate solution for importing create react app projects into Django, it needs to work for both CRA production builds as well as with the CRA development server.

The package cra-build-watch provides one solution to this problem. However, a bug in the package here prevents this from being the recommended solution for users of Django Manifest Loader.

This script might be worth investigating as an alternate solution.

@devo-wm
Copy link

devo-wm commented May 25, 2022

For those looking for a solution without "ejecting" your app from the restraints of create-react-app = there are some packages that can help you modify write the development server files to disk; see blog post here: https://marmelab.com/blog/2021/07/22/cra-webpack-no-eject.html.

We're using craco and made one small change to our devServer configuration in our craco.config.js below:

module.exports = {
...
    devServer: {
        writeToDisk: true,
    },
...

And here's our custom CRAManifestLoader:

import fnmatch
from manifest_loader.loaders import LoaderABC

class CRAManifestLoader(LoaderABC):
    @staticmethod
    def get_single_match(manifest, key):
        return manifest['files'].get(key, key)

    @staticmethod
    def get_multi_match(manifest, pattern):
        matched_files = [file for file in manifest['entrypoints'] if
                         fnmatch.fnmatch(file, pattern)]
        return matched_files

Description of the entrypoints key from react-scripts source:

"entrypoints" key: Array of files which are included in index.html, can be used to reconstruct the HTML if necessary

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.

None yet

2 participants