Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9996d2

Browse files
feat(dev-server): don't deepmerge exportConditions. allow user config to fully replace the default
1 parent b20cc19 commit d9996d2

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

.changeset/tidy-spoons-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/dev-server': patch
3+
---
4+
5+
Fix an issue where the nodeResolve plugin wasn't accepting user configuration correctly
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { fileURLToPath } from 'url';
2+
import { resolve } from 'path';
3+
4+
export default {
5+
rootDir: resolve(fileURLToPath(import.meta.url), '..', '..', '..'),
6+
appIndex: '/demo/export-conditions/index.html',
7+
nodeResolve: {
8+
exportConditions: ['default']
9+
},
10+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<html>
2+
<body>
3+
<img width="100" src="../logo.png" />
4+
5+
<h1>Node resolve demo</h1>
6+
<p>A demo which resolves bare module imports</p>
7+
8+
<div id="test"></div>
9+
10+
<script type="module">
11+
// inline bare modules are resolved
12+
import { render, html } from 'lit-html';
13+
14+
window.__inlineNodeResolve = !!render && !!html;
15+
</script>
16+
17+
<script type="module">
18+
19+
window.__tests = {
20+
// lit-html only adds this global in development mode
21+
// so when the exportCondition is overwritten, it'll be undefined
22+
prodExport: typeof window.litIssuedWarnings === 'undefined',
23+
};
24+
document.getElementById('test').innerHTML = `<pre>${JSON.stringify(
25+
window.__tests,
26+
null,
27+
2,
28+
)}</pre>`;
29+
</script>
30+
</body>
31+
</html>

packages/dev-server/src/plugins/nodeResolvePlugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export function nodeResolvePlugin(
1414
extensions: ['.mjs', '.js', '.cjs', '.jsx', '.json', '.ts', '.tsx'],
1515
moduleDirectories: ['node_modules', 'web_modules'],
1616
// allow resolving polyfills for nodejs libs
17-
preferBuiltins: false,
18-
exportConditions: ['development'],
17+
preferBuiltins: false
1918
},
2019
userOptionsObject,
2120
);
2221

22+
// use user config exportConditions if present. otherwise use ['development']
23+
options.exportConditions = userOptionsObject.exportConditions || ['development'];
24+
2325
return rollupAdapter(
2426
nodeResolve(options),
2527
{ preserveSymlinks },

packages/dev-server/test/integration.test.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const testCases = [
3333
name: 'syntax',
3434
tests: ['stage4', 'inlineStage4', 'importMeta', 'staticImports', 'dynamicImports'],
3535
},
36+
{
37+
name: 'export-conditions',
38+
tests: ['prodExport'],
39+
},
3640
];
3741

3842
describe('integration tests', () => {

0 commit comments

Comments
 (0)