我的package.json文件如下:
{
"name": "xxxx",
"version": "1.0.0",
"private": true,
"devDependencies": {
"grunt": "^1.0.4",
"grunt-autoprefixer": "^3.0.4",
"grunt-contrib-cssmin": "^3.0.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-package-modules": "^1.0.0",
"grunt-sass": "^3.1.0",
"node-sass": "^4.12.0"
},
"dependencies": {
"bootstrap": "^4.2.1",
"jquery": "^3.3.1",
"popper.js": "^1.14.6"
}
}
我有一个Gruntfile.js,它执行某些任务,例如文件监视,SASS编译,自动前缀,缩小...
示例任务:
sass: { // sass tasks
dist: {
options: {
compass: true, // enable the combass lib, more on this later
style: 'expanded', // we don't want to compress it
implementation: sass,
sourceMap: true
},
files: {
'web/var/static/css/main.css': 'web/var/static/sass/main.scss' // this is our main scss file
}
}
},
我的node_modules文件夹在项目根目录下。整个项目不是公开的,只是/web/var/static/
中的所有项目。
所需的库(例如bootstrap,jquery和popper.js)应该可以公开访问,因为它们部分直接包含在项目视图中,例如/var/static/lib/jquery/dist/jquery.min.js
。否则,我将它们与自定义的grunt任务粘合在一起。
当前grunt将依赖项放入项目根目录下的node_modules文件夹中。我该怎么说,要把那些特定的依赖项放到公用/var/static/lib/
文件夹中?
答案 0 :(得分:0)
与此同时,我通过使用https://www.npmjs.com/package/grunt-contrib-copy
解决了这个问题使用此模块,您可以将所需的文件复制到项目目录中:
copy: {
jquery: {
files: [{src: ['**'], dest: 'web/var/static/lib/jquery',expand: true, cwd: 'node_modules/jquery/dist'}],
},
popper: {
files: [{src: ['**'], dest: 'web/var/static/lib/popper.js',expand: true, cwd: 'node_modules/popper.js/dist'}],
},
}
有些替代方案,例如https://www.npmjs.com/package/grunt-copy-deps,它们仅复制具体的库文件。这样比较舒适,但是我喜欢只复制所需内容的灵活性。