React-native-web: Is it possible for react-native-web to import *.web.js if one exists (to allow use alongside native modules)

Created on 22 Jul 2016  路  5Comments  路  Source: necolas/react-native-web

I'd like to do the following and wondering if it's possible:

// create files
Foo.ios.js
Foo.android.js
Foo.web.js

import Foo from 'foo';

Most helpful comment

In order to make it also work with Typescript (*.web.tsand *.web.tsx) there 2 more actions required:

In web-pack configuration set following extensions:
extensions: ["", ".web.js", ".js", ".web.jsx", ".jsx", ".web.ts", ".ts", ".web.tsx", ".tsx"],

In tsconfig.json add following settings into the compilerOptions:

"baseUrl": ".",
"paths": {
    "*": [
        "*.web",
        "*"
    ]

All 5 comments

That might be more of a question for the React-Native folks since they're the ones that make the tools

The current packager code is here: https://github.com/facebook/react-native/tree/master/packager
You might be able to just add the change and submit a PR

Yeah, webpack should load *.web.js files by default. So if you're using that you build your web entry, it should work.

In order to make it also work with Typescript (*.web.tsand *.web.tsx) there 2 more actions required:

In web-pack configuration set following extensions:
extensions: ["", ".web.js", ".js", ".web.jsx", ".jsx", ".web.ts", ".ts", ".web.tsx", ".tsx"],

In tsconfig.json add following settings into the compilerOptions:

"baseUrl": ".",
"paths": {
    "*": [
        "*.web",
        "*"
    ]

But this doesn't seem to work with server side code. Everything is taken to the default .js files. Any help ??

Was this page helpful?
0 / 5 - 0 ratings

Related issues

passion0470 picture passion0470  路  3Comments

shirakaba picture shirakaba  路  3Comments

holmesal picture holmesal  路  3Comments

MovingGifts picture MovingGifts  路  3Comments

buffaloDeveloper picture buffaloDeveloper  路  3Comments