-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can use fs.readFile ? #102
Comments
Same here, how to do it the right way? |
same here |
1 similar comment
same here |
You can use a plugin like https://github.com/quadric/babel-plugin-inline-import to swap fs.read for a require statement. |
@cliedeman It'll work well introduced with babel-node even if we use sequelize-cli , thanks. |
I had the same issue, but it just needed a tweak with Sequelize to work. Where it's using const model = sequelize['import'](path.resolve(path.join(__dirname, file))); I'd suggest this isn't a problem with this repository, just on oversight on the automatically generated code by the Sequelize CLI. For reference, the full Sequelize 'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.js')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = sequelize['import'](path.resolve(path.join(__dirname, file)));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db; |
Instead of using |
I use backpack with sequelize .
This code generate file like
and this code needs reading static files.
These code doesn't work after build because __dirname points relative path from build path which differ from pre-located .
This happens as well as other codes using reading files. Is there any idea?
Js dynamic import case , I resolve this situation by using require.context
like
require.context(__dirname ,false,/\.\/(?!index).*\.js$/)
.But, it's uneasy to manage codes. Is there any idea?
The text was updated successfully, but these errors were encountered: