How can I serve NPM packages using Flask?

后端 未结 3 1296
执笔经年
执笔经年 2020-12-24 12:40

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.

W

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 13:11

    You need Bower and you already have NPM. This is all you need to achieve what you want.

    Basically, you will have to create a package.json in the root to install Bower using NPM. Then you will have to create a bower.json to define what all libraries you need, example jQuery.

    Then your flow will be like:

    npm install
    bower install
    

    This will basically install bower for you and the other frontend libraries you defined in bower.json.

    All bower components will go into a directory called bower_components in your root. This is where all your installed bower packages will reside. You can use these packages inside your templates now.

    Also see this to make sure that bower's packages are installed in your static or assets folder which you want to serve.

提交回复
热议问题