妥当な数の依存関係を持つきれいな標準タスクをまとめましたが、何らかの理由で実際に依存関係をロードするのに1〜3分かかります。私は普通のことを少しでも新しくしていますが、極端な遅さについての他の質問のほとんどは、数秒の時間を引用しているので、間違ったことをやっていると思います。 package.jsonからGrunt:依存関係のロードには数分かかります
const path = require("path");
module.exports = function(grunt) {
require('jit-grunt')(grunt);
require('time-grunt')(grunt);
const ignoredSourceScriptPatterns = ['!**/*.debug.js', '!**/*.min.js', '!scripts/*', '!**/*.map'],
baseUIPath = 'presentation/ui',
scripts = grunt.file.expand({filter: 'isFile',
matchBase: true,
cwd: baseUIPath},
['*.js', ...ignoredSourceScriptPatterns]);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
build: {
cwd: 'presentation/',
src: 'ui/**',
dest: path.join('presentation', 'static'),
expand: true
}
},
uglify: {
options: {
sourceMap: true,
compress: false
},
build: {
cwd: baseUIPath,
files: function() {
var modules = grunt.file.expand({
filter: 'isDirectory',
expand: true,
cwd: 'presentation/ui/modules'
}, ['**', '!**/css', '!**/scripts', ...ignoredSourceScriptPatterns]),
components = grunt.file.expand({
filter: 'isFile',
expand: true,
cwd: 'presentation/ui'
}, ['components/!*.js', ...ignoredSourceScriptPatterns]),
files, componentFiles;
files = modules.map(function(path) {
var modulePath = `modules/${path}/scripts`,
moduleName = modulePath.split('/').reduce(function(result, next) {
var nameFragment;
switch(next) {
case "modules":
nameFragment = "Poptart.";
break;
case "scripts":
nameFragment = "min.js";
break;
default:
nameFragment = `${next.charAt(0).toUpperCase() + next.slice(1)}.`;
break;
}
return result + nameFragment;
}, "");
return {
src: grunt.file.expand({
filter: 'isFile'
}, [`${baseUIPath}/${modulePath}/*.js`, ...ignoredSourceScriptPatterns]).sort(
function(a, b) {
return a.length - b.length;
}
),
dest: `${baseUIPath}/${modulePath}/${moduleName}`
};
});
componentFiles = components.map(function(componentPath) {
return {
src: `${baseUIPath}/${componentPath}`,
dest: `${baseUIPath}/${componentPath.replace('.js', '.min.js')}`
};
});
files = [...files, ...componentFiles];
files.push({
src: grunt.file.expand({
filter: 'isFile'
}, [`${baseUIPath}/*.js`, ...ignoredSourceScriptPatterns]),
dest: `${baseUIPath}/poptart.min.js`
});
return files;
}(),
extDot: 'last',
expand: true
}
},
cssmin: {
options: {
sourceMap: true
},
build: {
cwd: 'presentation/static/ui/',
src: ['**/*.css', '!css/jquery-ui/**', '!css/ionicons/**', '!**/*.min.js'],
dest: 'presentation/static/ui/',
ext: '.min.css',
expand: true
}
},
eslint: {
options: {
configFile: 'presentation/build/eslint.json',
ignorePath: 'presentation/build/.eslintignore'
},
target: ['presentation/**/*.js', '!presentation/ui/scripts/*', '!presentation/static/**']
},
shell: {
test: {
command: 'python manage.py test -p "*tests.py"',
options: {
stdout: true,
failOnError: true
}
}
},
karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: true
}
},
mochaTest: {
unit: {
options: {
reporter: 'spec'
},
src: ['presentation/test/server/*.js']
}
}
});
/*grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-newer');*/
grunt.registerTask('default', ['lint', 'test']);
grunt.registerTask('test', ['shell:test', 'mochaTest:unit', 'karma:unit']);
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('build-static', ['uglify', 'copy', 'cssmin']);
};
そして、私のdevの依存関係:ここで
は私gruntfileは次のようになります。
- は使用:
"devDependencies": { "chai": "^3.5.0", "chai-jquery": "^2.0.0", "eslint": "^3.7.1", "grunt": "^1.0.1", "grunt-contrib-copy": "^1.0.0", "grunt-contrib-cssmin": "^1.0.2", "grunt-contrib-uglify": "^2.0.0", "grunt-eslint": "^19.0.0", "grunt-karma": "^2.0.0", "grunt-mocha-test": "^0.13.2", "grunt-newer": "^1.2.0", "grunt-shell": "^1.3.1", "jit-grunt": "^0.10.0", "jquery": "^3.1.1", "karma": "^1.3.0", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jquery-chai": "^0.1.3", "karma-mocha": "^1.3.0", "karma-phantomjs-launcher": "^1.0.2", "karma-sinon": "^1.0.5", "mocha": "^3.2.0", "sinon": "^1.17.6", "sinon-chai": "^2.8.0", "time-grunt": "^1.4.0" }
は、ここで私はこれまで試したものです作業を読み込むことが実際に問題であったことを確認するために時間を浪費します。そうだった。実際に実行されているタスクは非常に合理的な時間を要しました。
- jit-gruntを使用しています。これは顕著な違いはありませんでした。
- npmプルーン。これは実際にはかなり大きな(〜30秒)差をつけましたが、依然としてタスクローディングのための完全に不合理な時間に私を残します。
- いくつかの依存関係の削除とアンロード(uglify、copy、cssmin)私はこの問題(最初はテスト/リンキング作業をしたばかりで、すべてが素早くうまくいった)を見始めた頃に追加しました。これも顕著な違いはありませんでした。
So.この尺度で他に何が遅くなるのでしょうか?
ありがとうございました!
にあなたが使用している持っていない場合は、ファイル
私は間違いなく、これらのすべてが目的を果たしています。これは私の実際の製品で使用したいかもしれないものと遊ぶための私のサンドボックスアプリです。ここにはランダムなものがいくつかあります。いずれにしても、私はこの遅さを見始める前に、すべてがそこに戻っていたので、彼らは問題の核心ではないようです。 –
私はそれぞれのセクションをひとつずつコメントアウトして、どこで問題が起こっているのかを見てみることにしました。それ以外の場合は 'node_modules'フォルダを削除してから' npm install'を再度実行してください。 – timothyclifford