Last active
March 8, 2023 13:42
-
-
Save elawad/c0af86ea37629ad0538c2b974b4ea0c1 to your computer and use it in GitHub Desktop.
Sequelize using ES Module imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('@babel/register')({ | |
presets: [ | |
['@babel/preset-env', { targets: { node: 'current' } }] | |
] | |
}); | |
const path = require('path'); | |
const DB_PATH = 'dist/db'; // use dist instead of src directory | |
module.exports = { | |
'config': path.resolve(DB_PATH, 'config.json'), | |
'models-path': path.resolve(DB_PATH, 'models'), | |
'seeders-path': path.resolve(DB_PATH, 'seeders'), | |
'migrations-path': path.resolve(DB_PATH, 'migrations') | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "module", | |
"engines": { | |
"node": ">=14.18", | |
"yarn": ">=1.22" | |
}, | |
"scripts": { | |
"start": "node --experimental-specifier-resolution=node src", | |
"db": "sequelize db:migrate && sequelize db:seed:all", | |
"predb": "yarn dist", | |
"dist": "cp -r src dist", | |
"predist": "rm -rf dist", | |
"postdist": "node setup-dist.js" | |
}, | |
"dependencies": { | |
"@babel/core": "^7.16.0", | |
"@babel/preset-env": "^7.16.0", | |
"@babel/register": "^7.16.0", | |
"sequelize": "^6.8.0", | |
"sequelize-cli": "^6.2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { writeFileSync } from 'fs'; | |
const file = './dist/package.json'; | |
const data = '{ "type": "" }'; // to override ESM in main package.json | |
writeFileSync(file, data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment