{"id":2098,"date":"2014-01-02T11:55:49","date_gmt":"2014-01-02T08:55:49","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=2098"},"modified":"2026-04-03T15:32:43","modified_gmt":"2026-04-03T12:32:43","slug":"building-dhtmlx-library-with-grunt","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/building-dhtmlx-library-with-grunt\/","title":{"rendered":"Building the DHTMLX Library with Grunt"},"content":{"rendered":"<p>\n        <div class=\"info-block\">\n            <div class=\"info-icon\">\n                <svg viewBox=\"0 0 14 16\">\n                    <path fill-rule=\"evenodd\" d=\"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z\"><\/path>\n                <\/svg>\n\n                INFO\n            <\/div>\n\n            <div class=\"info-content\">\n                <p>\n                    If you are using an outdated version of DHTMLX Suite 5 and require the documentation for it, \n                    please <a href=\"https:\/\/dhtmlx.com\/docs\/contact.shtml\" title=\"\">contact us<\/a>, <br \/>and we will send it to you.\n                <\/p>\n            <\/div>\n        <\/div>\n    <br \/>\n<a href=\"https:\/\/gruntjs.com\/\">Grunt<\/a> is a JavaScript task runner. It is like a swiss knife of JavaScript development. Due to the multiple plugins, Grunt can be used for wide set of tasks: file preprocessing, code minification, code linting, publishing, etc. In this article we will show how to use Grunt to compile a single file from the dhtmlxSuite package.<\/p>\n<p>If you want, you can skip the technical details and <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/tutorials\/dhtmlx-with-grunt.zip\">download the final Grunt solution<\/a>.<\/p>\n<p>&nbsp;<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2013\/12\/dhtmlx-grunt.png\" alt=\"Build DHTMLX with Grunt\" title=\"Build DHTMLX with Grunt\" width=\"456\" height=\"240\" class=\"aligncenter size-full wp-image-2115\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2013\/12\/dhtmlx-grunt.png 456w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2013\/12\/dhtmlx-grunt-300x157.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/p>\n<p>&nbsp;<br \/>\n<strong>Getting Started<\/strong><\/p>\n<p>To run Grunt you need to have <a href=\"https:\/\/nodejs.org\/en\/\">Node.js<\/a> and <a href=\"https:\/\/www.npmjs.com\/\">npm<\/a> installed. Also, we will use the <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/dhtmlxSuite.zip\">dhtmlxSuite Standard package<\/a> (open source, GPL-ed). The solution will work with any version of dhtmlxSuite so you can use the existing version.<\/p>\n<p><strong>Creating package.json<\/strong><\/p>\n<p>Lets create a <em>package.json<\/em> in the root folder of the dhtmlx package. This file will have the list of modules which we need for file building:<\/p>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\"><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"st0\">&quot;name&quot;<\/span>: <span class=\"st0\">&quot;dhtmlx&quot;<\/span>,<br \/>\n&nbsp; <span class=\"st0\">&quot;version&quot;<\/span>: <span class=\"st0\">&quot;3.6.0&quot;<\/span>,<br \/>\n&nbsp; <span class=\"st0\">&quot;devDependencies&quot;<\/span>: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;grunt&quot;<\/span>: <span class=\"st0\">&quot;~0.4.1&quot;<\/span>,<br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;grunt-contrib-uglify&quot;<\/span>: <span class=\"st0\">&quot;~0.2.5&quot;<\/span>,<br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;grunt-contrib-concat&quot;<\/span>: <span class=\"st0\">&quot;~0.3.0&quot;<\/span>,<br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;grunt-replace&quot;<\/span>: <span class=\"st0\">&quot;~0.5.1&quot;<\/span>,<br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;grunt-contrib-cssmin&quot;<\/span>: <span class=\"st0\">&quot;~0.6.2&quot;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Now run the next two commands from the command line:<\/p>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">npm <span class=\"kw2\">install<\/span> <span class=\"re5\">-g<\/span> grunt-cli<br \/>\nnpm <span class=\"kw2\">install<\/span><\/div><\/div>\n<p>The first line will install the Grunt command line interface. The second line will install the dependencies from the <em>package.json<\/em>.<\/p>\n<p>&nbsp;<br \/>\n<strong>Creating Gruntfile<\/strong><\/p>\n<p>Now lets create our build file. <!--more-->It must be named &#8220;<strong>Gruntfile<\/strong>&#8220;:<\/p>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">module.exports = <span class=\"kw1\">function<\/span><span class=\"br0\">&#40;<\/span>grunt<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n<br \/>\n&nbsp; grunt.initConfig<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; pkg:grunt.file.readJSON<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'package.json'<\/span><span class=\"br0\">&#41;<\/span>,<br \/>\n&nbsp; &nbsp; concat: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; options: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; separator: <span class=\"st_h\">';\\n'<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; dhtmlx:<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: <span class=\"st0\">&quot;dhtmlx&quot;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; src: <span class=\"br0\">&#91;<\/span><span class=\"st_h\">'dhtmlxForm\/sources\/dhtmlxcommon.js'<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st_h\">'dhtmlxForm\/sources\/dhtmlxform.js'<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st_h\">'dhtmlxForm\/sources\/ext\/dhtmlxform_*.js'<\/span><span class=\"br0\">&#93;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; dest: <span class=\"st_h\">'dist\/&lt;%= concat.dhtmlx.name %&gt;.js'<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span>,<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span>,<br \/>\n&nbsp; &nbsp; uglify: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; dhtmlx:<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; files: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st_h\">'dist\/&lt;%= concat.dhtmlx.name %&gt;.min.js'<\/span>: <span class=\"br0\">&#91;<\/span><span class=\"st_h\">'&lt;%= concat.dhtmlx.dest %&gt;'<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n&nbsp; grunt.loadNpmTasks<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'grunt-contrib-uglify'<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; grunt.loadNpmTasks<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'grunt-contrib-concat'<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; grunt.loadNpmTasks<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'grunt-contrib-cssmin'<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; grunt.loadNpmTasks<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'grunt-replace'<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n<br \/>\n&nbsp; grunt.registerTask<span class=\"br0\">&#40;<\/span><span class=\"st_h\">'dhtmlx'<\/span>, <span class=\"br0\">&#91;<\/span><span class=\"st_h\">'concat:dhtmlx'<\/span>, <span class=\"st_h\">'uglify:dhtmlx'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n<span class=\"br0\">&#125;<\/span>;<\/div><\/div>\n<p>The top part of the file defines possible operations. As you can see, there are two major sections: &#8220;concat&#8221; and &#8220;uglify&#8221;. The first one contais the list of files needed to be combined. The most important element here is &#8220;src&#8221; array. It contains all files, which we want to process. <\/p>\n<p>You can also notice that we can use file masks and templates so there is no need to enter all files one by one. Just specify the mask, and all matching files will be included. <\/p>\n<p>The second part contains configuration for code compressor. It is quite simple and can be used as is for any kind of build.<\/p>\n<p>After these operations, the config file contains a set of commands that enables different Grunt tasks. At the last line, the config file contains our new task &#8211; &#8220;dhtmlx&#8221;, which is combined from combining and compression tasks.<\/p>\n<p>Now when you have <em>package.json<\/em> and <em>Gruntfile<\/em>, you can run the following command from the console:<\/p>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">grunt dhtmlx<\/div><\/div>\n<p>and Grunt will build the <em>dhtmlx.js<\/em> and <em>dhtmlx.min.js<\/em> files in &#8220;<strong>dist<\/strong>&#8221; subfolder. The target files will contain combined and compressed files that we have defined in the configuration file. With above configuration, the result files will include dhtmlxForm with all its extensions. By adding other files into the <em>Grunfile<\/em> configuration you can create a custom build which will include files that are necessary for your app.<\/p>\n<p>An alternative way is to use the ready-to use <em>Gruntfile<\/em> which is configured to build the full dhtmlxSuite library.<\/p>\n<p>&nbsp;<br \/>\n<strong>Config for DHTMLX Suite<\/strong><\/p>\n<p>The <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/tutorials\/dhtmlx-with-grunt.zip\">attached archive<\/a> contains ready-to use <em>package.json<\/em> and <em>Gruntfile<\/em>. You can extract these files to the root of the dhtmlxSuite folder and run the following commands:<\/p>\n<ul>\n<li>to build a basic grid:<\/li>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">grunt grid<\/div><\/div>\n<li>to build a grid with all extensions:<\/li>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">grunt gridfull<\/div><\/div>\n<li>to build a basic form:<\/li>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">grunt form<\/div><\/div>\n<li>to build a form with all extensions:<\/li>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">grunt formall<\/div><\/div>\n<li>to build the full dhtmlx Suite as a single file:<\/li>\n<div class=\"codecolorer-container bash default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\">grunt dhtmlx<\/div><\/div>\n<\/ul>\n<p>The result files will be saved in the &#8220;<em>dist<\/em>&#8221; subfolder.<\/p>\n<p>&nbsp;<br \/>\n<strong>Afterthought<\/strong><\/p>\n<p>Of course, you can also use the LibCompiler tool that comes with the dhtmlxSuite but there is no clear winner. The LibCompiler provides an easy GUI but works only with the predefined configuration. Grunt requires a manual configuration but gives more flexibility for build process. Which one to choose depends on your needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grunt is a JavaScript task runner. It is like a swiss knife of JavaScript development. Due to the multiple plugins, Grunt can be used for wide set of tasks: &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3800,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,71,1,38],"tags":[33,42,14,39,10],"class_list":["post-2098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts-for-codeproject-com","category-tutorials","category-uncategorized","category-visible","tag-all-posts","tag-grunt","tag-tips","tag-nodejs","tag-dhtmlxsuite"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/2098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=2098"}],"version-history":[{"count":4,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/2098\/revisions"}],"predecessor-version":[{"id":15353,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/2098\/revisions\/15353"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3800"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=2098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=2098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=2098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}