Code Monkey home page Code Monkey logo

Comments (13)

ericf avatar ericf commented on May 4, 2024

@santiagoaguiar Are there docs on browserify and webpack on how to handle different entry points other than what's in "main" in the package.json file?

If so, then yes, we can address this by creating a browser.js or whatever for creating a CommonJS entry point suitable for the browser.

from formatjs.

santiagoaguiar avatar santiagoaguiar commented on May 4, 2024

Yes, both browserify and webpack support it, based on this spec.

In webpack you need to configure the field explicitly, by using the resolve.PackageAlias field.

On browserify, it uses the "browser" field if present, as seen here.

from formatjs.

ericf avatar ericf commented on May 4, 2024

@santiagoaguiar okay, adding a "browser" field to the package.json sounds good. /cc @caridy

If you want to take a stab at this, that would be great! Feel free to open a PR, and we can discuss the details in the PR, and once we get things figured out for one package, we can expand this pattern to all of the other FormatJS packages.

from formatjs.

kyleboyle avatar kyleboyle commented on May 4, 2024

👍 Count my vote for this

from formatjs.

ericf avatar ericf commented on May 4, 2024

Closing this now that #40 has been merged.

from formatjs.

ericf avatar ericf commented on May 4, 2024

Released in v1.0.2.

from formatjs.

kyleboyle avatar kyleboyle commented on May 4, 2024

Thanks, tested and works, cut out the ~220kb from my webpack bundle.

from formatjs.

steffenmllr avatar steffenmllr commented on May 4, 2024

Also trying to get this to work with browserify. Is there an example on how to switch and set languages with browserify ?

from formatjs.

kyleboyle avatar kyleboyle commented on May 4, 2024

These links will probably be helpful:
https://github.com/gpbl/react-locale-hot-switch
remix-run/react-router#484 (comment)

from formatjs.

steffenmllr avatar steffenmllr commented on May 4, 2024

Thanks @kyleboyle I saw the react-locale-hot-switch. I still don't get how to load and or change a local. It there a sample app using browserify and react-intl somewhere?

from formatjs.

kyleboyle avatar kyleboyle commented on May 4, 2024

In that project, take a look in i18n/index.js. You just need to use browserify in the same way that webpack is being used to split bundles and async load. Specifically in webpack, require.ensure introduces a bundle split point and does async loading of the split bundle. I'm sure browserify would have a similar mechanism. You can see how the individual language files in that directory are loaded as separate bundles.

from formatjs.

gpbl avatar gpbl commented on May 4, 2024

The idea behind react-locale-hot-switch is to create a chunk for each language, containing the required files: your localized messages and the various locale-data needed by react-intl (and eventually other localised stuff, as moment.js locales).

When a user changes the language, the relative chunk is injected into the browser (with webpack) and the new localized messages are passed as props to the component tree, forcing the components to re-render. (I have no idea how browserify manages this code injection nor how to create chunks with it)

Anyway I understand it's not a simple task: a faster way is just to reload the page and let the server include the proper <script>s with the localized data.

from formatjs.

steffenmllr avatar steffenmllr commented on May 4, 2024

Thanks for the help guys! I took the easy way and just reloaded the page for now :)

from formatjs.

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.