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

Conversation

piu130
Copy link
Contributor

@piu130 piu130 commented Aug 31, 2018

As described in the react-native-web doc there is the new file extension .web.js{x} needed for significant platform differences.
This PR adds those extensions.
Discussion see here.

Fixes #1056.

Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Thank you for the PR :-)

@@ -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.

@piu130 piu130 changed the title added .web.js{x} resolve extensions to webpack for better react-native-web support Fixes #1056 added .web.js{x} resolve extensions to webpack for better react-native-web support Sep 3, 2018
@piu130 piu130 changed the title Fixes #1056 added .web.js{x} resolve extensions to webpack for better react-native-web support Fixes #1056: added .web.js{x} resolve extensions to webpack for better react-native-web support Sep 3, 2018
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Sorry for not spotting this before, but could you add some tests to:
https://github.com/neutrinojs/neutrino/blob/master/packages/react/test/react_test.js

I'd just put inside the "valid preset {production, development, test}", like the web preset does:

test('valid preset production', t => {
process.env.NODE_ENV = 'production';
const api = new Neutrino();
api.use(mw());
const config = api.config.toConfig();
// Common
t.is(config.target, 'web');
t.deepEqual(config.resolve.extensions, expectedExtensions);
t.is(config.optimization.runtimeChunk, 'single');
t.is(config.optimization.splitChunks.chunks, 'all');
// NODE_ENV/command specific
t.true(config.optimization.minimize);
t.false(config.optimization.splitChunks.name);
t.is(config.devtool, undefined);
t.is(config.devServer, undefined);
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();
// Common
t.is(config.target, 'web');
t.deepEqual(config.resolve.extensions, expectedExtensions);
t.is(config.optimization.runtimeChunk, 'single');
t.is(config.optimization.splitChunks.chunks, 'all');
// NODE_ENV/command specific
t.false(config.optimization.minimize);
t.true(config.optimization.splitChunks.name);
t.is(config.devtool, 'cheap-module-eval-source-map');
t.not(config.devServer, undefined);
t.is(config.devServer.host, '0.0.0.0');
t.is(config.devServer.port, 5000);
t.is(config.devServer.public, 'localhost:5000');
t.is(config.devServer.publicPath, '/');
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.is(config.target, 'web');
t.deepEqual(config.resolve.extensions, expectedExtensions);
t.is(config.optimization.runtimeChunk, 'single');
t.is(config.optimization.splitChunks.chunks, 'all');
// NODE_ENV/command specific
t.false(config.optimization.minimize);
t.true(config.optimization.splitChunks.name);
t.is(config.devtool, undefined);
t.is(config.devServer, undefined);
const errors = validate(config);
t.is(errors.length, 0);
});

Thanks :-)

@piu130
Copy link
Contributor Author

piu130 commented Sep 4, 2018

Missed that :) Done.

@eliperelman eliperelman changed the title Fixes #1056: added .web.js{x} resolve extensions to webpack for better react-native-web support Added .web.js{x} resolve extensions to webpack for better react-native-web support Sep 5, 2018
@edmorley
Copy link
Member

edmorley commented Sep 6, 2018

Re creating a shared test config (saw the email notification, though the message isn't above any more) - we're thinking of switching to Jest at some point (#635), which will mean we can use the snapshots feature and so avoid the manual duplication/boilerplate :-)

@edmorley edmorley added this to the v9 milestone Sep 6, 2018
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Many thanks for the PR! :-)

@kopax
Copy link

kopax commented Feb 15, 2020

Hello, I am trying hard to distribute react-native packages with extensions support from node_modules, .web.js, .android.js, .js (see https://stackoverflow.com/questions/60195490/how-to-distribute-package-for-expo-web-js-js-configuration)

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

Add .web.js and .web.jsx to resolve extension
3 participants