I created an javascript app using Oracle JET v2.0. Running
grunt build:release
creates release folder in the project root folder. How to change this to point to another path, for example outside project root?
I created an javascript app using Oracle JET v2.0. Running
grunt build:release
creates release folder in the project root folder. How to change this to point to another path, for example outside project root?
如果您使用的是 Yeoman 生成器,则可以按照 Grunt 流程中的scripts/grunt/tasks/build.js
. 您将在下面if (target === "release")
看到它按顺序运行许多任务。
不幸的是,发布文件夹名称在许多这些任务的配置文件中是硬编码的。因此,在 build:release 任务的末尾添加一个任务以将构建的版本复制到新目录中可能更有意义。您可以将目标添加到scripts/grunt/config/copy.js
名为 myFinalRelease 的文件中:
module.exports = {
release:
{
src: [
"**",
"!bower_components/**",
"!grunt/**",
"!scripts/**",
"!js/**/*.js",
"js/libs/**",
"!js/libs/**/*debug*",
"!js/libs/**/*debug*/**",
"!node_modules/**",
"!release/**",
"!test/**",
"!.gitignore",
"!bower.json",
"!Gruntfile.js",
"!npm-shrinkwrap.json",
"!oraclejetconfig.json",
"!package.json"
],
dest: "release/",
expand: true
},
myFinalRelease:
{
cwd: 'release/',
src: ['**'],
dest: "myRelease",
expand: true
}
};
然后将该 task:target 作为复制步骤添加到 release 部分的最后一行scripts/grunt/tasks/build.js
:
...
if (target === "release")
{
grunt.task.run(
[
"clean:release",
"injector:mainReleasePaths",
"uglify:release",
"copy:release",
"requirejs",
"clean:mainTemp",
"copy:myFinalRelease"
]);
}
...
为了使它更健壮,如果您正在执行大量 build:release'ing,您应该执行一些额外的清理任务,因为除非您创建任务来执行它,否则 myRelease 文件夹不会被清除。或者您可能会查看其他 Grunt 插件,例如 grunt-contrib-rename。
如果这对于您的口味来说太多复制并且太混乱,您可以编辑所有硬编码的任务配置以更改发布目录的名称。您会发现目录名称显示在这四个文件中:
scripts/grunt/config/clean.js
...
release: ["release/*"],
...
scripts/grunt/config/uglify.js
...
dest:"release/js"
...
scripts/grunt/config/copy.js
...
dest: "release/",
...
scripts/grunt/config/require.js
...
baseUrl: "./release/js",
name: "main-temp",
mainConfigFile: "release/js/main-temp.js",
optimize: "none",
out: "release/js/main.js"...
...