[英]Grunt - output 2 versions of web app
I'm learning Grunt and trying to sort out how I can create 2 versions of the same application. 我正在学习Grunt,并试图弄清如何创建同一应用程序的2个版本。 The difference between the two are configuration settings.
两者之间的区别是配置设置。
Ideally, I would like the process to output 2 versions. 理想情况下,我希望该过程输出2个版本。 One with a boolean in one of the .js files set to false, the other left to true.
一个在一个.js文件中将布尔值设置为false,另一个设置为true。 I would also need to concat and minify then file.
我还需要合并并最小化然后归档。
Is there a recommended way to do this? 有推荐的方法吗? Thanks in advance
提前致谢
You can specify 2 configurations in your grunt.initConfig
您可以在
grunt.initConfig
指定2种配置
grunt.initConfig({
myTask: {
version1: { ... }
version2: { ... }
}
})
And then register your default task to run each of these versions 然后注册您的默认任务以运行每个版本
grunt.task.registerTask("default", ["myTask:version1", "myTask:version2"])
Or just some other task name, myTaskAllVersions
instead of default
或者只是其他一些任务名称,
myTaskAllVersions
而不是default
名称
You could use this versioning to flip your .js boolean, per version 1 or 2. 您可以使用此版本控制按版本1或2翻转.js布尔值。
A similar approach could be taken to minifying and concatting the files afterwards, ie 之后可以采用类似的方法来缩小和压缩文件,即
grunt.initConfig({
minify: {
version1: { ... }
version2: { ... }
}
})
and 和
grunt.task.registerTask("default", ["myTask:version1", "minify:version1"])
You could do all of this with the uglifyjs grunt task . 您可以使用uglifyjs grunt任务来完成所有这些工作 。
Here's an example of the config for your Gruntfile: 这是您的Gruntfile的配置示例:
grunt.initConfig({
uglify: {
app1: {
files: {
'dist/app1.min.js': [
'src/app1.js',
'src/common.js'
]
}
},
app2: {
files: {
'dist/app2.min.js': [
'src/app2.js',
'src/common.js'
]
}
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.