[英]Grunt package.json: How to install dependencies to public subfolder?
我的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
。 否則,我將它們與自定義的咕unt聲任務粘合在一起。
當前,grunt將依賴項放入項目根目錄下的node_modules文件夾中。 我該怎么說呢,把那些特定的依賴項放到公共的/var/static/lib/
文件夾中?
同時,我已經通過使用以下方法解決了此問題: 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 ,它們僅復制具體的庫文件。 這樣比較舒適,但是我喜歡僅復制所需內容的靈活性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.