Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Added .web.js{x} resolve extensions to webpack for better react-native-web support #1064

Merged
merged 3 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ module.exports = (neutrino, opts = {}) => {
});

neutrino.config.resolve.alias.set('react-native', 'react-native-web');

neutrino.config.resolve.extensions.prepend('.web.js');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment linking to the react-native-web docs, and also a Fixes #1056 to the commit message/PR description? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I am trying hard to distribute react-native packages with extensions support from node_modules, .web.js, .android.js, .js , I don't get how to tell react-native application to import the correct file when node_modules. I am not able to tell the webapp to import .web.js first, too when import happen from node_modules, I initialized my project with expo SDk36, do you know how I can solve my issue? Thanks again for reading.

neutrino.config.resolve.extensions.prepend('.web.jsx');
};
24 changes: 22 additions & 2 deletions packages/react/test/react_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { validate } from 'webpack';
import Neutrino from '../../neutrino/Neutrino';

const mw = () => require('..');
const newExtensions = ['.web.jsx', '.web.js'];
const originalNodeEnv = process.env.NODE_ENV;

test.afterEach(() => {
Expand All @@ -22,18 +23,37 @@ test('valid preset production', t => {
process.env.NODE_ENV = 'production';
const api = new Neutrino();
api.use(mw());
const config = api.config.toConfig();

const errors = validate(api.config.toConfig());
// Common
t.deepEqual(config.resolve.extensions.slice(0, newExtensions.length), newExtensions);

const errors = validate(config);
t.is(errors.length, 0);
});

test('valid preset development', t => {
process.env.NODE_ENV = 'development';
const api = new Neutrino();
api.use(mw());
const config = api.config.toConfig();

const errors = validate(api.config.toConfig());
// Common
t.deepEqual(config.resolve.extensions.slice(0, newExtensions.length), newExtensions);

const errors = validate(config);
t.is(errors.length, 0);
});

test('valid preset test', t => {
process.env.NODE_ENV = 'test';
const api = new Neutrino();
api.use(mw());
const config = api.config.toConfig();

// Common
t.deepEqual(config.resolve.extensions.slice(0, newExtensions.length), newExtensions);

const errors = validate(config);
t.is(errors.length, 0);
});