Automatically concatenates all dependencies based on simple rules you specify in the referenced files.
Main features:
- Nested importing using @import(filepath)
- File referencing: @partof(filepath)
- Importing through glob: @import('glob:components/*.js')
- "JIT-settings": @option('setting_key', 'new_setting_value')
- Per-file output-control: @saveto('../../lib.js')
- Generalized templating for controlling headers, footers, output filenames and more
- Compatible through Sublime 2.x to Sublime 3.x
(Not yet supported, hopefully in the future) The easiest way to get started is to install the package using Sublime Package Control.
Open the pallete by pressing CTRL + SHIFT + P (Win, Linux) or CMD + SHIFT + P (OS X). Type install and the command palette should filter down Package Control: Install Package. Select this command by either clicking on it, or using your cursor keys to highlight it and pressing Enter.
In the pallete that follows type Concat and look for File Concatenator. Select this command in the same manner as before and when the installation is finished you are good to go!
If you for some reason cannot or will not use Package Control, you can install the plugin manually be using the instructions below.
- In Sublime, click the Preferences > Browse Packages… button in the menu
- Download the latest release
- Unpack it into the Packages/ directory
- Restart Sublime Text
Personalize your settings by opening Preferences > Package Settings > File Concatenator > Settings - Default and copying them into Preferences > Package Settings > File Concatenator > Settings - Default.
You can always define overwrite specific settings by using the @option method.
The plugin works by analysing the targeted file for certain commands. If found, it will be executed and stripped from the source code before writing the finished concatenated file. There are four commands available:
###@import(filepath)### The only command you'll really need for small projects. Replaces the @import(filepath)-line with the contents of filepath.
C:\wwwroot\main.js
// Dependency1.js
@import('components/dependency1.js')
C:\wwwroot\components\dependency1.js
+-----------------------------+
| |
| Hello! I am dependency1.js! |
| |
+-----------------------------+
C:\wwwroot\main.cat.js
// Dependency1.js
+-----------------------------+
| |
| Hello! I am dependency1.js! |
| |
+-----------------------------+
###@partof(filepath)### Tells the intepreter to look for references of this file in filepath. This allows for the concatenation progress to start from both the parent (main.js) and the child (dependency1.js):
dependency1.js
@partof('../main.js')
+-----------------------------+
| |
| Hello! I am dependency1.js! |
| |
+-----------------------------+
###@saveto(filepath)### The default behaviour is to save the concatenated file in the same directory as the source file. You can easily specify an alternative path by using the @saveto-command:
C:\wwwroot\main.js
// Dependency1.js
@import('components/dependency1.js')
@saveto('builds/main.js')
In the example above we also gave it a specific name. If we had just specified the 'builds/'-folder the name given had been as per the "tpl_output_filename-setting" (more on that below).
If the directory does not exist the plugin will ask if you want it to create it for you.
You can @saveto as many paths as you like by just passing the command multiple times: C:\wwwroot\main.js
// Dependency1.js
@import('components/dependency1.js')
@saveto('builds/main.js')
@saveto('../../otherproject/vendor/dependency.js')
@saveto('\\server\shared\latest\stuff.js')
###@option(key, value, recursive=False)### Sublime File Concatenator has very a extensive and flexible settings file. But because of the nature of this plugin, all settings can't apply very good to all files and projects at all times.
By using the @option-command you can temporarily overwrite the global plugin settings. Settings specified via @option only apply the file that is currently being handled and gets removed when the file has finished parsing or when a value of "default" has been passed.
C:\wwwroot\main.js
// Dependency1.js
@import('components/dependency1.js')
@saveto('builds/') // Here we choose only to specify an directory for output
@option('tpl_output_filename', '{{this.fileroot}}-{{system.date}}.{{this.extension}}')
C:\wwwroot\builds\main-2014-05-26.js
// Dependency1.js
+-----------------------------+
| |
| Hello! I am dependency1.js! |
| |
+-----------------------------+
####Recursive flag#### If we want all children to be affected by the JIT-setting we can turn on recursion by passing True as a third argument:
C:\wwwroot\main.js
// Dependency1.js
@import('components/dependency1.js')
@saveto('builds/')
@option('tpl_output_filename', '{{this.fileroot}}-{{system.date}}.{{this.extension}}')
@option('tpl_child_header', '/**! BOF {{system.time}}: {{this.filename}} ({{this.filesize}}) */\n', True)
@option('tpl_child_footer', '\n/**! EOF {{this.filename}} */\n\n', True)
C:\wwwroot\builds\main-2014-05-26.js
// Dependency1.js
/**! BOF 19:48: dependency1.js (159.0 B) */
+-----------------------------+
| |
| Hello! I am dependency1.js! |
| |
+-----------------------------+
/**! EOF dependency1.js */
###glob:### This magic prefix activates Python's glob module and passes your argument directly to it. Whatever comes out, gets imported.
C:\wwwroot\main.js
// My dependencies:
@import('glob:components/*.js') // Import all Javascript-files in the components-directory
@saveto('builds/')
@option('tpl_output_filename', '{{this.fileroot}}-{{system.date}}.{{this.extension}}')
C:\wwwroot\builds\main-2014-05-26.js
// My dependencies:
+-----------------------------+
| |
| Hello! I am dependency1.js! |
| |
+-----------------------------+
+-----------------------------+
| |
| Hello! I am dependency2.js! |
| |
+-----------------------------+
###Starting the concatenation process### CTRL + SHIFT + C or CMD + Shift + C will start the concatenation process. You can also specify concatenation on Save, read more under the Settings-section below.
###The settings file###
- Open the default settings via Preferences -> Package Settings -> File Concatenator -> Settings - Default.
- Copy the contents into Preferences -> Package Settings -> File Concatenator -> Settings - User
There is a lot of documentation in the settings file. Don't be put of though, it's actually really easy.
- Fork it.
- Create a branch (git checkout -b sublime_file_concatenator)
- Commit your changes (git commit -am "Fixed regex...")
- Push to the branch (git push origin sublime_file_concatenator)
- Open a Pull Request
- Tada!
###v0.9.7###
- Fixed an issue where the file communicated as written actually was a file containing one or more "@saveto" statements.
- Added support for multiple @saveto`s.
###v0.9.5###
- Removed 'popup_files_not_found'-setting (this will always pop if warnings occur)
- Added trim_parents-setting
- Added trim_children-setting
- Added trim_output-setting
- Added date_format-setting
- Added time_format-setting
- Added {{mustasche_style}}-templating options accessable via the settings, with a great number of namespaced variables.
- Added @saveto-method
- Added @option-method
- Added glob:-prefix
- Added multi-level @import
- Added optimizations which greatly improved overall runtime
- Added support for Sublime 3 Beta
###v0.8.5###
- Added changelog
- Added popup for referenced files that could not be found.
- Added 'popup_files_not_found'-setting
- Added tests
- Fixed bug that didn't reset certain variables each run
- Cleaned up the regex's and the general code a bit
- Added support for multi-level @partof
###v0.8.0### Initial release