feats / babel-plugin-inline-import

inline the raw content of import statements
https://www.npmjs.com/package/babel-plugin-inline-import
MIT License
243 stars 29 forks source link

can not work with react native #23

Open sophister opened 5 years ago

sophister commented 5 years ago

hi, I've setup .babelrc like this:

{
    "presets": ["module:metro-react-native-babel-preset"],
    "plugins": [
        [
            "inline-import",
            {
                "extensions": [".md", ".text", ".txt"]
            }
        ],
        [
            "module-resolver",
            {
                "root": ["./src"],
                "alias": {}
            }
        ]
    ]
}

But cli throw error as below:

error: bundling failed: Error: Unable to resolve module `./button.spec.md` from `/Users/jess/jess/renrendai/source/rrd-react-native/storybook/stories/button.story.js`: The module `./button.spec.md` could not be found from `/Users/jess/jess/renrendai/source/rrd-react-native/storybook/stories/button.story.js`. Indeed, none of these files exist:
  * `/Users/jess/jess/renrendai/source/rrd-react-native/storybook/stories/button.spec.md(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
  * `/Users/jess/jess/renrendai/source/rrd-react-native/storybook/stories/button.spec.md/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
    at ModuleResolver.resolveDependency (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:120:15)
    at ResolutionRequest.resolveDependency (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:49:18)
    at DependencyGraph.resolveDependency (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/node-haste/DependencyGraph.js:218:16)
    at Object.resolve (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/lib/transformHelpers.js:141:30)
    at dependencies.map.result (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:373:31)
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:369:18)
    at /Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:188:33
    at Generator.next (<anonymous>)
    at step (/Users/jess/jess/renrendai/source/rrd-react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:298:30)
 BUNDLE  [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
iamswain25 commented 5 years ago

it doens't work for me either, when I import a file, the plugin looks for it in node_modules

inf3cti0n95 commented 5 years ago

No solution for this?

aliustaoglu commented 5 years ago

You need to add this to metro.config.js:

const metroDefault = require('metro-config/src/defaults/defaults.js');
...
  resolver: {
    sourceExts: metroDefault.sourceExts.concat(['md', 'sql', 'txt']),
  }
....

Then it's all sweet. I think this should be mentioned in readme.

timotgl commented 1 year ago

Also not working with react-native 0.64.2 for me despite configuring the metro config (adding html to sourceExts).

It works when testing an app locally on a physical iOS device, but not with Xcode cloud/test flight.