Referencing resources in node_modules folder

梦想的初衷 提交于 2019-12-21 06:28:43

问题


I am currently in the process of writing my first Node.js app. I recently installed bootstrap via the npm (following instructions on bootstrap's web site) and was wondering the "standard" way of referencing the bootstap.min.css (and other files of interest). It is best to use grunt/gulp to copy (bundle and minify) the resources I need into my project structure?

Any help would be appreciated.


回答1:


I was able to copy with the node_modules bootstrap resources with a simple Grunt task:

copy: {
    bootstrapSrcCss: {
      src: "./node_modules/bootstrap/dist/css/bootstrap.css",
      dest: "./public/src/css/bootstrap.css"
    },
    bootstrapSrcJs: {
      src: "./node_modules/bootstrap/dist/js/bootstrap.js",
      dest: "./public/src/js/bootstrap.js"
    }
}

Using grunt plug-in: grunt-contrib-copy




回答2:


As explained in This Blog Post, you can create a "Static Route" instead of exposing the node_modules structure totally.

app.use('/scripts', express.static(__dirname + '/node_modules/bootstrap/dist/'));

But that may not be the best method. It seems that packages that come with resources also come with Grunt files as well.



来源:https://stackoverflow.com/questions/28749396/referencing-resources-in-node-modules-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!