我的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将依赖项放到项目根目录下的node_modules文件夹中。我该怎么说才能将这些特定的依赖项放到公共/var/static/lib/
文件夹中呢?
发布于 2019-09-09 13:21:24
同时,我使用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,它只复制具体的库文件。这要舒服得多,但我喜欢只复制我需要的东西的灵活性。
https://stackoverflow.com/questions/57853758
复制相似问题