-
Notifications
You must be signed in to change notification settings - Fork 53
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
Access static files (templates) #32
Comments
@hlegendre did you try relative paths? |
@goncaloneves yes. That's what I tried first. But the node process is launched from /var/task whereas the handler.js file is in a deep folder _optimize/XXX/. Therefore any relative path is relative to /var/task and not the handler.js containing folder... And I don't know beforehand this folder. |
You need to have the optimize prefix at the lowest level same of your
source.
I am still not visualizing your project structure but if you follow SLS
recommendation it should work fine.
About Browserify transforms is a no.
Right now I dont have time for features in my hands, if you have the will
and find a solution for your problem I welcome you to do a PR. 😎
|
I don't think the structure of my project has an impact since your plugin optimizes everything (except the textual templates I include as well) into a single js file. The output is therefore something along
where I did not want to rely on opening the liquid files through I was hoping there would be a way to get the path to I guess there is no apparent way to do it. I'll probably try something dirty like exploring the Regarding the PR, I do not know much about Browserify so I am not sure I would be able to help but I'll have a look. Thanks anyway. |
You said you tried using relative paths, I recommend you try again.
In your structure is easy to call any template file from within your lambda
just using `./templateFolder/file.liquid`. Why do you need full path? Using
relative paths in relation to your handler file should be enough.
Then add the same liquid file with includePaths and it will be included
creating the same folder structure you have before bundling.
If this is not enough and only solved by full path then you need to hack
lambda runtime path + optimize prefix + your file path.
|
Since everything is "optimized" by your plugin, I get a single handler.js file which is then deployed to Any additional folders I chose to copy using the I would not have problems with I managed to make it work by using |
Hugues that's perfect. 3 issues opened about this and you brought the solution. 👍 I will add this information to the readme file. |
you're welcome ! |
For anyone looking at this, remember that if you are using subfolders the asset will get deployed to them and that needs to be taken into account. E.g. myLambda:
handler: mySubFolder/myLambda.handler
optimize:
includePaths: ['mySubFolder/myFile.json'] path.resolve(process.env.LAMBDA_TASK_ROOT, '_optimize', process.env.AWS_LAMBDA_FUNCTION_NAME, 'mySubFolder/myFile.json') |
Do we include the below line in serverless.yml? path.resolve(process.env.LAMBDA_TASK_ROOT, '_optimize', process.env.AWS_LAMBDA_FUNCTION_NAME, 'mySubFolder/myFile.json') And what if my function depends on multiple json files? |
@GoChartingAdmin, that is the line you include when importing it into the serverless function. e.g. const path = require('path')
const myJson = require(path.resolve(process.env.LAMBDA_TASK_ROOT, '_optimize', process.env.AWS_LAMBDA_FUNCTION_NAME, 'mySubFolder/myFile.json')) |
Hi,
I am trying to deploy a serverless function that requires access to liquid templates.
I managed to include the static files in the bundle through the "includePath" config parameters but I am unable to get a path to them.
This is because the node process calling the handler is not in the same folder as the handler itself. Hence I cannot find a path to the handler (that I can then prefix to the path of my templates) to fs.readFile them... I tried using __dirname, but Browserify changes it while bundling to the path at the time of compilation...
Would you have any idea of how to make it work, please ?
PS: I explored the https://github.com/JohnPostlethwait/stringify way but I cannot define additional transforms to browserify in serverless-plugin-optimize, can I ?
BR,
Hugues
The text was updated successfully, but these errors were encountered: