Open augonis opened 5 years ago
Hi, @augonis! I am not sure, that I have got your point. Can you explain a little bit more about the reproduce case? What kind of bundler do you use to build your javascript? You can also look through the example here - https://github.com/ttag-org/CRA-runtime-example/blob/master/app/src/App.js#L4 It's the very basic starter for Create React App that uses webpack for the build and modules resolve logic.
I'm working on a web app using pwa-starter-kit and serving it in development with polymer-cli, it doesn't transpile or bundle in develoment, just rewrites module imports from module specifiers to URLs ( import 'ttag'
> import '../../node_modules/ttag/dist/index.js'
) for the browser. Unfortunately ttag/dist/index.js is not an ES6 module exporting anyting.
For production builds I'll probably use webpack, but that's ways off.
It would be great to include ttag as ES6 module in npm distribution for those using plain ES6 modules.
@augonis thanks for the clarification!
Going to try pwa-starter-kit
and see how we can solve this. As far as I know, we can distribute valid es6 format via module
property in the package.json
- https://github.com/rollup/rollup/wiki/pkg.module. But we should check that at first.
I guess I have found https://pwa-starter-kit.polymer-project.org/faq
If the library’s pkg.main is not already ESM, check if package.json defines pkg.module or pkg[‘jsnext:main’] - our tools will prefer those if present.
I remember, that we tried to distribute es6 via pkg.module
property earlier, but the common scenario for webpack and other build systems is to not transpile what is inside the node_modules
and if we will add pkg.module
webpack will use those imports and that can break existing builds.
So, as I can see there are a couple ways to solve this issue:
import { t } from 'ttag/es6'
pkg[‘jsnext:main’]
in the package.json
This option will work if it will not break existing webpack setups that excludes node_modules
from been transpiled.
What do you think, guys? @MrOrz @vharitonsky @alxpy
I prefer first way.
I am also for the first way.
So, to fix this issue we need to:
dedent
, and plural-forms
. We can put dedent
right inside the ttag repo. Not sure that we can do the same with plural-forms
. babel-plugin-ttag
to recognize ttag/es6
imports.As far as I can see it makes sense to use rollup instead of webpack for ttag distribution. It seems like it can easily distribute es6 modules format + produces smaller bundle size.
The project website and npm page (in usage examples) suggests that the package is distributed in es6 module format, but that doesn't seem to be the case. Doing
npm install --save ttag
and puttingimport { t, ngettext, msgid } from 'ttag'
in my sites javascript makes the browser goThe requested module '../../node_modules/ttag/dist/index.js' does not provide an export named 't'
.