Skip to content

Commit

Permalink
Aug 4, 2024, 1:37 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 4, 2024
1 parent 6ad4041 commit 4163925
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
3 changes: 3 additions & 0 deletions dailyNotes/2024-08-04.md
Original file line number Diff line number Diff line change
@@ -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
51 changes: 22 additions & 29 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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: [
Expand All @@ -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',
Expand Down

0 comments on commit 4163925

Please sign in to comment.