[英]Yeoman Gruntfile.js - add a vendors directory to the dist build
[英]set directory for node_modules within gruntfile.js
我想在gruntfile.js中设置node_modules目录的路径。 我想为我的所有grunt项目都有一个中心node_module目录。
是否可以设置外部node_module目录的路径?
当前设置(有效)
projekt1 --gruntfile.js --package.json --node_modules projekt2 --gruntfile.js --package.json --node_modules
设置我想要的
node_modules project1 --gruntfile.js --package.json project2 --gruntfile.js --package.json
你可以....我一直在使用这个设置没有任何问题。 在每个项目Gruntfile.js
文件中,只需将基数设置为一个目录,如下所示:
给定这样的文件夹结构:
node_modules
project1
app.js
Gruntfile.js
package.json
您的Gruntfile.js
可能看起来像这样
module.exports = function(grunt) {
// Tell grunt where to find node_modules
// This is the line you're looking for
grunt.file.setBase('../');
// Your normal grunt config
grunt.initConfig({
// Your package.json file is now relative to the parent folder
pkg: grunt.file.readJSON('project1/package.json'),
// I use webpack, your tasks will probably be different
webpack: {
options: {},
build: {
// Paths are now resolved from the upper folder
// since we set the base path to one level up
entry: './project1/app.js',
output: {
// Again, the path must be relative to the parent folder
path: 'project1',
filename: 'app.min.js'
}
}
}
// etc...
});
// Load tasks...
}
设置setBase('../')
您需要确保所有文件路径都已正确解析,因为基本路径已更改为1级。
警告...如果您发布或分发您的软件包,Grunt任务将不适用于下载它的人,因为他们很可能不会与node_modules 1级别相同的设置。 即使他们这样做,他们也可能不会将project1
文件夹命名为相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.