Cuando se va a deployar a producción y se genera la aplicación con Sencha CMD, es necesario quitar los mensajes de console.log, info, etc, regularmente se hace la busqueda de los strings y se van eliminando manualmente. Peroooo

Sencha CMD usa Ant, y esto es una gran ventaja, se pueden programar tareas de tal forma que todo se realice en un mismo proceso sin intervención de tal forma que se obtenga por ejemplo el app.js limpio de mensajes de debug (console).

La forma de hacerlo es simple. Si no tienes el archivo build.xml en la raiz de tu proyecto crealo, y si lo tienes agrega estas lineas.

 


<?xml version="1.0" encoding="utf-8"?>
<project name="projectX" default=".help">
<!--
The build-impl.xml file imported here contains the guts of the build process. It is
a great idea to read that file to understand how the process works, but it is best to
limit your changes to this file.
-->
<import file="${basedir}/.sencha/app/build-impl.xml"/>

<!--
The following targets can be provided to inject logic before and/or after key steps
of the build process:

The "init-local" target is used to initialize properties that may be personalized
for the local machine.

<target name="-before-init-local"/>
<target name="-after-init-local"/>

The "clean" target is used to clean build output from the build.dir.

<target name="-before-clean"/>
<target name="-after-clean"/>

The general "init" target is used to initialize all other properties, including
those provided by Sencha Cmd.

<target name="-before-init"/>
<target name="-after-init"/>

The "page" target performs the call to Sencha Cmd to build the 'all-classes.js' file.

<target name="-before-page"/>
<target name="-after-page"/>

The "build" target performs the call to Sencha Cmd to build the application.

<target name="-before-build"/>
<target name="-after-build"/>
-->
<target name="-before-build">
<delete dir="${build.dir}" includes="**"/>
</target>
<target name="-after-build">
<copy todir="${build.dir}" >
<fileset dir="${app.dir}" includes="index.php"/>
<fileset dir="${app.dir}" includes="robots.txt"/>
<fileset dir="${app.dir}" includes=".htaccess"/>
</copy>
<delete file="${build.dir}/resources/Readme.md"/>
<delete file="${build.dir}/index.html"/>

<strong><copy file="${build.dir}/app.js" tofile="${build.dir}/app_debug.js" /> </strong>
<strong> <replaceregexp match="console\.(?:warn|log|error|con|info)(\((?:(?>[^()]+))*\));" replace="" flags="g" file="${build.dir}/app.js" /></strong>

</target>

</project>

 

El truco esta primero en crear una copia del app.js y luego remplazar todo lo que encuentre de “console”

Cable aclarar que no esta probado para todos los casos.

 

Que el código los acompañe!!

Share
  1. Angel M says:

    Excelente aporte,

    Otra forma de eliminar los mensajes de console es utilizando los tags:

    //
    console.log(“Mensaje”);
    //

    Cualquier línea de código entre esas dos etiquetas será eliminada -incluyendo las mismas etiquetas- al momento de construir la aplicación (sencha app build).

    Espero sea de utilidad.

    Saludos.

  2. Jak says:

    Te refieres a los tags:

    //< debug>
    
    //</debug>
    
  3. Jak says:

    Vaya eso es nuevo, esos tags no existian cuando escribi este post! Muchas gracias por el aporte!