UNPKG

5.86 kBMarkdownView Raw
1# Asset-Mate
2Asset-Mate auto-generates a gulpfile based on a manifest, which enables you to easily compile, rewrite, copy, or deploy Javascript, ES6 and React with Browserify, SCSS, CSS and images
3
4UPDATES:
51) The babel es6 transformer now handles React too
62) Calling watch on gulp now watches all files in directories alongside js/scss/css globs
73) You can now specify an 's3CacheControl' option to set the default cache-control header on all the assets
8
9###How it works
101) You fill in a manifest of your source-tree assets, and desired destinations
11
122) It auto-generates a gulp file
13
143) Call 'watch', or 'build' with gulp to have it make your output assets
15
164) Call 'deploy' with gulp to have it deployed to an AWS S3 bucket
17
18###What it can do
19- Compile ES6 files
20- Compile SASS files
21- Minify ES6 or Javascript files
22- Autoprefix CSS files (automatic cross-browser support)
23- Do find and replace (rewrites) on all text files
24- Create multiple output sizes of images
25- Simple copying of files
26- Deploy to an S3 bucket
27- Keeps an internal list of files (so that you don't copy everything every time)
28
29###Requirements
30- Node and NPM
31- Ffmpeg (If you want to resize images)
32
33###Installation
341) npm install -g asset-mate
35
362) cd to the root of your project directory
37
383) asset-mate new
39
40###Commands
41- asset-mate new
42- asset-mate autogenerate
43- asset-mate clearcache
44- gulp (build | deploy | watch)
45- gulp (build | deploy | watch) [--src 0] [ --dest 0]
46- gulp (build | deploy | watch) [--src src_name] [ --dest dest_name]
47
48###Usage
49When you call 'asset-mate new' it installs gulp and the dependencies you need to run the gulp file, and adds a 'gulp-manifest.json' file to the root of your project.
50
51'gulp-manifest.json' will start with an example structure that you can fill in with the details of your own project. You can have multiple sources and multiple destinations, and it understands arrayed and glob format descriptions of your files.
52Once you've finished describing your manifest, call 'asset-mate autogenerate'. This will build your gulp file for you. Then use the commands 'gulp build' or 'gulp watch' to have it produce your assets.
53
54If you specify 's3Bucket' and 'awsCredentialsProfile' in a destination in your manifest, calling 'gulp deploy' will use that information to automatically upload your files to the given S3 bucket. You can also specify an 's3Prefix' if you would like the files in that destination prefixed in the bucket.
55
56###Example
57A common example case is when you have a source directory that you would like compiled into three formats:
58
59- A local 'dev' folder in which sources are not minified
60- A local 'dist' folder in which sources are minified
61- A 'deploy' folder in which sources are both minified and any urls in those files point to S3 or CDN addresses
62
63Your gulp-manifest.json file for this use case might look as follows:
64
65```
66[
67 {
68 "name" : "my-app",
69 "src" : {
70 "directory" : "src",
71 "es6" : "js/*.js",
72 "js" : "other_file/js/*.js",
73 "scss" : "scss/*.scss",
74 "css" : "css/*",
75 "images" : [
76 {
77 "glob" : "images/**",
78 "sizes" : {
79 "big" : "100%",
80 "med" : 0.5
81 }
82 }
83 ],
84 "copy" : "**",
85 "copyExclude" : ["folder_to_exclude1/*", "folder_to_exclude2/*"]
86 },
87 "dest" : [
88 {
89 "name" : "dev",
90 "directory" : "dist_dev",
91 "minify" : false,
92 "autoprefix" : true,
93 "rewrites" : { "ASSET_URL" : "dist_dev" },
94 },
95 {
96 "name" : "dist",
97 "directory" : "dist",
98 "minify" : true,
99 "autoprefix" : true,
100 "rewrites" : { "ASSET_URL" : "" },
101 },
102 {
103 "name" : "deploy",
104 "directory" : "deploy",
105 "minify" : true,
106 "autoprefix" : true,
107 "rewrites" : { "ASSET_URL" : "aws-cdn.com" },
108 "s3Bucket" : "my-bucket",
109 "s3Prefix" : "app-asset",
110 "s3CacheControl" : "max-age=86400",
111 "awsCredentialsProfile" : "default"
112 }
113 ]
114 }
115]
116```
117
118You can omit any of the keys that are not relevant to your project and it should still build ok.
119
120(Note: I've also used this example to demonstrate that the images list will understand you specifying your sizes as both percentages and fractions)
121
122Since I've specified the copy glob as "**", when gulp runs it will copy and rewrite all files in the 'src' directory that don't match with those specified in the other globs, it will parse everything in the es6 glob using Babel and Browserify, it will resize my images and appended them with their size name (e.g. image_med.png), and it will compile and autoprefix any css.
123
124The results will vary as per the rules specified in each of the destinations
125
126When I call 'gulp deploy' it will ignore the first two destinations (as they don't list any s3 information) any only deploy the files in the third.
127
128If I only want to watch or build to a single destination, the second for example, I can call 'gulp build --src my-app --dest dist' or 'gulp build --src 0 --dest 1'
129
130Also, any subsequent times I run the build command it 'should' check the source files against their destinations and an internal record and only copy those with changes (this might be a bit flakey though)
131
132Oh and! Subsequent deploys should also upload only the files that have changed
133