Reputation: 41
Currently using grunt to minify all of my js files. I have a php script in my html that checks the url and decides whether to include one big minified javascript file or all of the regular javascript files. This is annoying because I have all of the files listed in two places; once in the grunt file and once in the switch statement in my php script. If someone on the team adds a new file to one but not the other, bad things happen. Is there an easier more efficient way to go about switching between the two? We want it so that our production server uses the minified code and our local dev environments use the un-minified code.
Upvotes: 1
Views: 276
Reputation: 1582
I see three options there.
+ mysite-dev
+ scripts
- myscript.min.js (the non-minified content)
index.html
+ mysite-prod
+ scripts
- myscript.min.js (the minified content)
index.html
+ mysite
+ scripts-all
- myscript.js
- myscript.min.js
+ scripts
- myscript.js > ../scripts-all/myscript.min.js
index.html
+ mysite
+ scripts-all
- myscript.js
- myscript.min.js
+ scripts
- version-prod.js
- version-dev.js
- version.js > version-prod.js
index.html
On my side, when I release a website I have a bash script which builds the website structure and files for both development and production based on a JSON description file.
The JSON description defines all the files to be served and tells whether they must be minified of not.
[
{
"file": "./index.html",
"minify": false
},
{
"file": "./scripts/app.js",
"minify": true
},
...
]
The bash script processes the description, minifies the files which have to be minified, and copies the resulting files to two distinct directories. The "development" files are kept as is while the "production" files are minified.
+ release
+ production
+ development
Then I select which version I want to expose (c.f.: solution #1). This lets me maintain one single code base which is minified (or not) depending on the target release type (development/production).
NOTE: It looks like there is no real clean solution to this situation as the served files may have a name which is not consistent with their content (i.e.: .min
for non minified files).
Upvotes: 0