Closed mchambaud closed 9 years ago
Hi pal, you could try:
patterns: [{
match: /<script id="config" \b[^>]*>([\s\S]*?)<\/script>/,
replacement: function(match, p1) {
return grunt.file.read(directory.build + "/" + p1 + "/config.json");
}
}]
HI @outaTiME,
Actually, I don't care about the content of the script, I want to replace it with the content of the config.json.
@outaTiME
this will not work.
replacement: function(match, p1) {
return grunt.file.read(directory.build + "/" + p1 + "/config.json");
}
When ever I call grunt or variables from replacement function it fails with "Warning: Error while processing "..." file
I can do
{
match: 'config',
replacement: '<%= environment %>'
},
but this will not work.
{
match: 'config',
replacement: function(){
return environment;
}
},
i again pal, i don't know how environment variable was define but it your grunt is defined like that it might be work:
{
match: 'config',
replacement: function() {
return grunt.config.get('environment');
}
},
checkout: http://gruntjs.com/api/grunt.config
it works ?
Unfortunately, no.
Mmm, probably something wrong in your gruntfile, do you want to share with us your fully file ?
El 23 sept 2015, a las 13:10, Michael Chambaud notifications@github.com escribió:
Unfortunately, no.
— Reply to this email directly or view it on GitHub.
My grunt file is massive.. Do you have a working example with? Otherwise I will start a fresh project to see if it works.
Here basic example:
Gruntfile.js
module.exports = function (grunt) {
// define the configuration for all the tasks
grunt.initConfig({
// environment
environment: 'dev',
// replace task
replace: {
config: {
options: {
patterns: [
{
match: 'config',
replacement: function() {
return grunt.config.get('environment');
}
}
]
},
files: [
{expand: true, flatten: true, src: ['fixtures/environment.txt'], dest: 'tmp/'}
]
}
}
});
// load tasks
grunt.loadNpmTasks('grunt-replace');
// default task
grunt.registerTask('default', [
'replace'
]);
};
fixtures/environment.txt:
@@config
tmp/environment.txt:
dev
Here the complete working example:
Updates ??
Sorry haven't had a chance to try until just now, it works =)
Thanks!
Hi,
I'm trying to replace a certain script with another one but I can't figure out out to insert the file at $1.
Here's my code, works but script tag goes away.
I already have a solution but I'm not happy with it, I though maybe there was a more elegant way to achieve this.