Referencing resources in node_modules folder

2020-06-30 01:35发布

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.

2条回答
该账号已被封号
2楼-- · 2020-06-30 01:48

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-06-30 01:54

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

查看更多
登录 后发表回答