如何确定TypeScript应用构建时所用aurelia-google-maps的分发版本?
Great question! Let's break this down first for your specific Aurelia + TypeScript setup with aurelia-google-maps, then cover the general approach for any npm package with multiple distribution builds.
How to Find Which
aurelia-google-maps Dist Version Your App Uses 1. Check the Package's package.json
Head to node_modules/aurelia-google-maps/package.json and look for these core fields—they dictate which build your tooling will pick:
exports: This is the modern, authoritative way packages define entry points. It often explicitly separates behavior forimportvsrequiresyntax, or even browser vs Node.js environments. For example:
Since you're using"exports": { ".": { "import": "./dist/native-modules/index.js", "require": "./dist/commonjs/index.js" } }import {Configure} from "aurelia-google-maps", this would directly map to thenative-modulesbuild.module: Points to the ES module (Native Modules/ES2015) entry. If noexportsexists, build tools like Webpack or Aurelia CLI will prioritize this first because ES modules support tree-shaking.main: The traditional entry point for CommonJS/AMD builds—tools fall back to this if noexportsormoduleis defined.
2. Verify Your Build Tool Configuration
- Aurelia CLI: When you initialized your project, you selected a module format (ES6/ESNext or CommonJS). If you picked ESNext, it defaults to
native-modulesores2015; for CommonJS, it uses thecommonjsdist folder. Double-check youraurelia.jsonunderbuild.loader.moduleKindto confirm. - Webpack: Webpack's default
resolve.mainFieldsprioritizesmoduleovermain, so it will pick the ES module build unless you've modified this config. Look in yourwebpack.config.jsfor:resolve: { mainFields: ['module', 'main'] // Default behavior for browser targets }
3. Test Directly (Most Reliable)
Nothing beats seeing it in action:
- Pick one dist folder (e.g.,
dist/native-modules), open its entry file (index.js), and add a temporary console log:console.log('Using aurelia-google-maps native-modules version'); - Run your app and check the browser console. If the log appears, that's the active version. If not, repeat with other dist folders until you find the one that logs.
- For Webpack users, run
webpack --stats detailedand search the output foraurelia-google-maps—you'll see the exact file path being loaded into your bundle.
General Approach for Any NPM Package with Multiple Dist Builds
For any package with multiple dist folders, follow this workflow:
- Start with
package.json: Checkexports,module,main, andbrowserfields.exportstakes precedence over all others. Thebrowserfield specifies builds optimized for browser environments (often AMD/SystemJS). - Understand Your Build Tool's Priorities:
- Vite/Rollup: Prioritize
exports.import, thenmodule, thenmain. - Webpack: Follows
resolve.mainFields(default:['browser', 'module', 'main']for browser targets). - Node.js (server-side): Uses
exports.requireormainif noexportsexists.
- Vite/Rollup: Prioritize
- Inspect the Build Output: Look at your bundled code. ES2015 builds use modern syntax like arrow functions and
const/let; CommonJS builds usemodule.exportsandrequire(); AMD builds includedefine()calls.
内容的提问来源于stack exchange,提问作者Loupi
相关产品推荐
相关产品推荐

