From 4163925439a767c0af5e74fb1f902e0733738297 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Sun, 4 Aug 2024 17:37:49 +0000 Subject: [PATCH] Aug 4, 2024, 1:37 PM --- dailyNotes/2024-08-04.md | 3 +++ rollup.config.js | 51 +++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 29 deletions(-) create mode 100644 dailyNotes/2024-08-04.md diff --git a/dailyNotes/2024-08-04.md b/dailyNotes/2024-08-04.md new file mode 100644 index 0000000..ab9239f --- /dev/null +++ b/dailyNotes/2024-08-04.md @@ -0,0 +1,3 @@ +# 2024-08-04 +Reconfigured rollup.config +Fixed imports for dist/mjs file, so that on compilation the 2 imports that need a .js extension added will have that \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index 63cab5a..11926d3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -7,7 +7,7 @@ import alias from '@rollup/plugin-alias'; import path from 'path'; let isMjsOutput = false; // Flag to track if we're generating .mjs output -function addJsExtension() { +function addJsExtension(isMjsOutput) { return { name: 'add-js-extension', resolveId(source, importer) { @@ -29,11 +29,30 @@ const customAliases = alias({ { find: '@acala-network/sdk/utils/storage', replacement: '@acala-network/sdk/utils/storage.js' } ] }); +// Handle mjs and cjs differently so we can add the proper file extensiosn to the mjs imports export default [ + // cjs + { + input: './src/index.ts', + output: { + file: './dist/index.cjs', + format: 'cjs', + }, + plugins: [ + json(), + typescript(), + babel({ + plugins: ['@babel/plugin-syntax-import-assertions'], + babelHelpers: 'bundled', + presets: ['@babel/preset-env'], + extensions: ['.js', '.ts'], + }), + ] + }, + // mjs { input: './src/index.ts', // Your main TypeScript file output: [ - { file: './dist/index.cjs', format: 'cjs' }, { file: './dist/index.mjs', format: 'es' } ], plugins: [ @@ -48,34 +67,8 @@ export default [ }), // Handling extension issues - addJsExtension(), - - // nodeResolve({ - // extensions: ['.js', '.ts'], - // preferBuiltins: true - // }), + addJsExtension(true), ], - // external: [ - // /^@polkadot\//, - // /^@acala-network\//, - // 'axios', - // 'lodash', - // 'ethers' - // ], - watch: { - // Set the flag when the .mjs output is being processed - buildStart() { - isMjsOutput = false; // Reset for each build - }, - output: { - // Set the flag for .mjs output - file: './dist/index.mjs', - format: 'es', - onwrite: () => { - isMjsOutput = true; - } - } - } }, { input: 'src/index.ts',