diff --git a/.changeset/tidy-spoons-work.md b/.changeset/tidy-spoons-work.md new file mode 100644 index 000000000..66b4b0668 --- /dev/null +++ b/.changeset/tidy-spoons-work.md @@ -0,0 +1,5 @@ +--- +'@web/dev-server': patch +--- + +Fix an issue where the nodeResolve plugin wasn't accepting user configuration correctly diff --git a/packages/dev-server/demo/export-conditions/config.mjs b/packages/dev-server/demo/export-conditions/config.mjs new file mode 100644 index 000000000..30c9ae91f --- /dev/null +++ b/packages/dev-server/demo/export-conditions/config.mjs @@ -0,0 +1,10 @@ +import { fileURLToPath } from 'url'; +import { resolve } from 'path'; + +export default { + rootDir: resolve(fileURLToPath(import.meta.url), '..', '..', '..'), + appIndex: '/demo/export-conditions/index.html', + nodeResolve: { + exportConditions: ['default'] + }, +}; diff --git a/packages/dev-server/demo/export-conditions/index.html b/packages/dev-server/demo/export-conditions/index.html new file mode 100644 index 000000000..7bda213f1 --- /dev/null +++ b/packages/dev-server/demo/export-conditions/index.html @@ -0,0 +1,31 @@ + +
+ + +A demo which resolves bare module imports
+ + + + + + + + diff --git a/packages/dev-server/src/plugins/nodeResolvePlugin.ts b/packages/dev-server/src/plugins/nodeResolvePlugin.ts index 6b34af7f3..f9f6a1a13 100644 --- a/packages/dev-server/src/plugins/nodeResolvePlugin.ts +++ b/packages/dev-server/src/plugins/nodeResolvePlugin.ts @@ -15,11 +15,13 @@ export function nodeResolvePlugin( moduleDirectories: ['node_modules', 'web_modules'], // allow resolving polyfills for nodejs libs preferBuiltins: false, - exportConditions: ['development'], }, userOptionsObject, ); + // use user config exportConditions if present. otherwise use ['development'] + options.exportConditions = userOptionsObject.exportConditions || ['development']; + return rollupAdapter( nodeResolve(options), { preserveSymlinks }, diff --git a/packages/dev-server/test/integration.test.mjs b/packages/dev-server/test/integration.test.mjs index e73f3bb9b..17a2ba372 100644 --- a/packages/dev-server/test/integration.test.mjs +++ b/packages/dev-server/test/integration.test.mjs @@ -33,6 +33,10 @@ const testCases = [ name: 'syntax', tests: ['stage4', 'inlineStage4', 'importMeta', 'staticImports', 'dynamicImports'], }, + { + name: 'export-conditions', + tests: ['prodExport'], + }, ]; describe('integration tests', () => { diff --git a/packages/test-runner-commands/browser/commands.d.ts b/packages/test-runner-commands/browser/commands.d.ts index 44bdef915..2281de658 100644 --- a/packages/test-runner-commands/browser/commands.d.ts +++ b/packages/test-runner-commands/browser/commands.d.ts @@ -138,7 +138,7 @@ export function sendMouse(payload: SendMousePayload): Promise