Skip to content

Commit

Permalink
enhance: Commonjs bundle uses native-compatible code (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Feb 10, 2020
1 parent 28dbbff commit 5da9047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/rest-hooks/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const dependencies = Object.keys(pkg.dependencies)
.filter(dep => !['@rest-hooks/normalizr', '@babel/runtime'].includes(dep));

const extensions = ['.js', '.ts', '.tsx', '.mjs', '.json', '.node'];
const nativeExtensions = ['.native.ts', ...extensions];
process.env.NODE_ENV = 'production';
process.env.BROWSERSLIST_ENV = 'legacy';

Expand All @@ -34,9 +35,9 @@ export default [
output: [{ file: pkg.unpkg, format: 'umd', name: 'restHook' }],
plugins: [
babel({
exclude: ['node_modules/**', '**/__tests__/**'],
exclude: ['node_modules/**', '/**__tests__/**'],
extensions,
rootMode: "upward",
rootMode: 'upward',
runtimeHelpers: true,
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
Expand All @@ -55,12 +56,13 @@ export default [
plugins: [
babel({
exclude: ['node_modules/**', '**/__tests__/**', '**/*.d.ts'],
extensions,
rootMode: "upward",
extensions: nativeExtensions,
rootMode: 'upward',
runtimeHelpers: true,
}),
resolve({ extensions }),
commonjs({ extensions }),
replace({ 'process.env.CJS': 'true' }),
resolve({ extensions: nativeExtensions }),
commonjs({ extensions: nativeExtensions }),
],
},
];
4 changes: 4 additions & 0 deletions packages/rest-hooks/src/resource/paramsToString.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ export default function paramsToString(
searchParams: Readonly<Record<string, string | number>>,
) {
const params = new URLSearchParams(searchParams as any);
try {
params.sort();
// eslint-disable-next-line no-empty
} catch {}
return params.toString();
}

0 comments on commit 5da9047

Please sign in to comment.