Skip to content

Commit

Permalink
fix issues dynamic import on Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
kenhyuwa committed Mar 25, 2021
1 parent 9473896 commit 655bced
Show file tree
Hide file tree
Showing 8 changed files with 510 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Project files
node_modules
dist
src/locale

# Log files
npm-debug.log*
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ All notable changes to this project will be documented in this file.

- Fix issues localization lazy load.

## [1.0.13]

- Fix issues dynamic import on Vite ([#12](https://github.com/kenhyuwa/litepie-datepicker/issues/12)).

[Released]: https://github.com/kenhyuwa/litepie-datepicker/
[1.0.0]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.0
[1.0.1]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.1
Expand All @@ -80,3 +84,4 @@ All notable changes to this project will be documented in this file.
[1.0.10]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.10
[1.0.11]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.11
[1.0.12]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.12
[1.0.13]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.13
13 changes: 10 additions & 3 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import babel from '@rollup/plugin-babel';
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars';
import PostCSS from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
import minimist from 'minimist';
Expand Down Expand Up @@ -101,7 +102,8 @@ if (!argv.format || argv.format === 'es') {
output: {
file: 'dist/litepie-datepicker.esm.js',
format: 'esm',
exports: 'named'
exports: 'named',
inlineDynamicImports: true
},
plugins: [
replace(baseConfig.plugins.replace),
Expand All @@ -119,7 +121,8 @@ if (!argv.format || argv.format === 'es') {
]
]
}),
commonjs()
commonjs(),
dynamicImportVars()
]
};
buildFormats.push(esConfig);
Expand All @@ -134,6 +137,7 @@ if (!argv.format || argv.format === 'cjs') {
file: 'dist/litepie-datepicker.ssr.js',
format: 'cjs',
name: 'LitepieDatepicker',
inlineDynamicImports: true,
exports: 'auto',
globals
},
Expand All @@ -143,7 +147,8 @@ if (!argv.format || argv.format === 'cjs') {
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
commonjs()
commonjs(),
dynamicImportVars()
]
};
buildFormats.push(umdConfig);
Expand All @@ -158,6 +163,7 @@ if (!argv.format || argv.format === 'iife') {
file: 'dist/litepie-datepicker.min.js',
format: 'iife',
name: 'LitepieDatepicker',
inlineDynamicImports: true,
exports: 'auto',
globals
},
Expand All @@ -168,6 +174,7 @@ if (!argv.format || argv.format === 'iife') {
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
commonjs(),
dynamicImportVars(),
terser({
output: {
ecma: 5
Expand Down
3 changes: 2 additions & 1 deletion dev/serve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default defineComponent({
},
setup() {
const away = ref(null);
const dateValue = ref('30 Oktober 2021 ~ 18 Februari 2023');
const dateValue = ref([]);
// const dateValue = ref('30 Oktober 2021 ~ 18 Februari 2023');
const shortcuts = () => {
return [
{
Expand Down
27 changes: 27 additions & 0 deletions exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path');
const fs = require('fs-extra');
const dayjsLocale = './node_modules/dayjs/esm/locale';
const localeSrc = './src/locale';

async function main() {
await fs.remove(localeSrc);
const locales = await fs.readdir(dayjsLocale);
for (const locale of locales) {
await fs.copySync(
`${dayjsLocale}/${locale}`,
path.join(__dirname, `./src/locale/${locale}`)
);
await fs.readFile(`${localeSrc}/${locale}`, 'utf8', function(err, data) {
if (err) return console.log(err);
const result = data.replace(/..\/index/g, 'dayjs');

fs.writeFile(`${localeSrc}/${locale}`, result, 'utf8', function(err) {
if (err) return console.log(err);
});
});
}
}

main().catch(err => {
console.error(err);
});
Loading

0 comments on commit 655bced

Please sign in to comment.