I have a small Flask app which currently sources jQuery and highlight.js from external servers. I'd like to make these local dependencies which I pull in via NPM.
What is the standard practice for this? Should I create package.json
file in the same directory as my static
and templates
directories and serve node_modules
as a separate static dir ala this question?
I'm packaging and distributing my app using pip
, so any solution needs to be compatible with that.
Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.
js and Flask is useful. The most common use is when we need to add Machine Learning to our website since it is easier to implement Machine Learning in Python (due to super helpful libraries) and connect it to Node. js using Flask, rather than implementing it all together in Node. js.
Go to your static folder and there initialize your npm project.
cd flask_app/static $ npm init
after installing and saving npm packages you can serve them like this:
<script src="{{ url_for('static', filename='node_modules/toastr/toastr.js')}}"></script>
credits to: https://codeburst.io/creating-a-full-stack-web-application-with-python-npm-webpack-and-react-8925800503d9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With