Ich möchte React.js + browserify in meine Sails.js-Anwendung integrieren.Sails.js mit React.js, wie geht das richtig?
Dazu verwende ich ein Grunt-Plugin grunt-react.
habe ich eine Datei /tasks/config/browserify.js
module.exports = function(grunt) {
grunt.config.set('browserify', {
//dev: {
options: {
transform: [ require('grunt-react').browserify ],
extension: 'jsx'
},
app: {
src: 'assets/jsx/app.jsx',
dest: '.tmp/public/js/app.js'
}
//}
});
grunt.loadNpmTasks('grunt-browserify');
};
Dann habe ich eine Linie in compileAssets.js
und syncAssets.js
hinzugefügt:
// compileAssets.js
module.exports = function (grunt) {
grunt.registerTask('compileAssets', [
'clean:dev',
'stylus:dev',
'browserify', // <<< this added
'copy:dev'
]);
};
und
// syncAssets.js
module.exports = function (grunt) {
grunt.registerTask('syncAssets', [
'stylus:dev',
'browserify', // <<< this added
'sync:dev'
]);
};
Dann ich eine Linie in copy.js
modifiziert.
// copy.js
module.exports = function(grunt) {
grunt.config.set('copy', {
dev: {
files: [{
expand: true,
cwd: './assets',
src: ['**/*.!(styl|jsx)'], /// <<< this modified
dest: '.tmp/public'
}]
},
build: {
files: [{
expand: true,
cwd: '.tmp/public',
src: ['**/*'],
dest: 'www'
}]
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
};
Und es hat funktioniert!
Aber ich denke, ich habe es nicht ganz richtig gemacht.
Wenn ich unkommentiert Linie dev: {
und }
in /tasks/config/browserify.js
wie folgt aus:
module.exports = function(grunt) {
grunt.config.set('browserify', {
dev: { /// <<< this uncommented
options: {
transform: [ require('grunt-react').browserify ],
extension: 'jsx'
},
app: {
src: 'assets/jsx/app.jsx',
dest: '.tmp/public/js/app.js'
}
} /// <<< this uncommented
});
grunt.loadNpmTasks('grunt-browserify');
};
Und wenn ich Änderungen in compileAssets.js
und syncAssets.js
:
// compileAssets.js
module.exports = function (grunt) {
grunt.registerTask('compileAssets', [
'clean:dev',
'stylus:dev',
'browserify:dev', // <<< this added :dev
'copy:dev'
]);
};
und
// syncAssets.js
module.exports = function (grunt) {
grunt.registerTask('syncAssets', [
'stylus:dev',
'browserify:dev', // <<< this added :dev
'sync:dev'
]);
};
es funktioniert nicht!
Lohnt es sich, sich darüber Gedanken zu machen?
Und warum funktioniert es nicht, wenn ich browserify: dev
in compileAssets.js
und syncAssets.js
Dateien hinzufügen?
Ich fand die richtige Lösung. –