From 7d7cf09a4cd7fa49391bb3a9fddc39ad9d16d1d6 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 10 Sep 2025 16:07:53 +0200 Subject: [PATCH] fix esm code to include extension '.js', so it could used directly in browser environments with importmaps --- README.md | 4 ++-- babel.config.js | 3 +++ package.json | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77e504650..f17687b97 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Day.js has great support for internationalization. But none of them will be included in your build unless you use it. ```javascript -import 'dayjs/locale/es' // load on demand +import 'dayjs/locale/es.js' // load on demand dayjs.locale('es') // use Spanish locale globally @@ -90,7 +90,7 @@ dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in A plugin is an independent module that can be added to Day.js to extend functionality or add new features. ```javascript -import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand +import advancedFormat from 'dayjs/plugin/advancedFormat.js' // load on demand dayjs.extend(advancedFormat) // use plugin diff --git a/babel.config.js b/babel.config.js index 2531938f6..778b8a811 100644 --- a/babel.config.js +++ b/babel.config.js @@ -14,6 +14,9 @@ module.exports = { loose: true } ] + ], + plugins: [ + ['add-import-extension', { extension: 'js' }] ] } } diff --git a/package.json b/package.json index 2c74cddc7..a4b02163c 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "@semantic-release/github": "^11.0.4", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^22.4.3", + "babel-plugin-add-import-extension": "^1.6.0", "babel-plugin-external-helpers": "^6.22.0", "cross-env": "^5.1.6", "eslint": "^4.19.1",