cloud
cloud copied to clipboard
Import Paths -- Always relative?
Do all imports have to be relative?
I prefer this:
import { bar } from '~/services/foo'
to this:
import { bar } from '../../services/foo'
In Serverless Framework, I accomplish it like this:
tsconfig.json
"compilerOptions": {
"baseUrl": "./src", <or lib, or whatever, doesn't matter>
"rootDir": ".",
"paths": {
"~/*": [
"*"
]
}
}
webpack.config.js
const path = require("path");
module.exports = {
resolve: {
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
alias: {
'~': path.resolve(__dirname, 'src')
}
},
Thanks for making this framework, love the direction, and I'm excited to try it out.
Hi! Serverless Cloud only performs transpiling of your sources, it doesn't actually use tsc - that said, I think we could probably accomodate ~
as a custom prefix for saying 'relative to the base of the cloud project', or maybe 'relative to the nearest package.json' ? relatively easily. There's a discussion underway here https://github.com/serverless/cloud/discussions/72 regarding monorepo support, in case you're interested.
Thanks @dougmoscrop, I think that adding ~
as a custom prefix would solve my problem perfectly.
I don't have an opinion on if it's relative to the nearest package.json or the root of the cloud project, as they're the same in my case.