fisx-packager-static
v0.2.5
Published
A static resource pack plugin for fisx.
Readme
fisx package plugin
A static resource pack plugin for fisx.
How to use
The plugin is default installed by fisx.
Notice The packTo file attribute is conflict with this pack plugin, so don't use it.
Add configure to fis-conf.js
fis.match('::package', {
packager: fis.plugin('static', {
amdConfig: {
baseUrl: '{%$host%}/asset'
},
inlineResourceConfig: false,
resourceConfigFile: function (defaultConfigFile, page) {
defaultConfigFile = defaultConfigFile.replace('/templates', '/asset');
return defaultConfigFile;
},
page: {
files: ['templates/**.tpl'],
packAsync: true
}
})
});Options
page -
Object:optionalconfigure the pack strategy by page file, support multi-page pack. By default, the pack module file will sync load using script element.files -
Array|Function:optionalconfigure the page files to pack, by default*.html, the array item value can begloborRegExp, of course you can pass a function to filter the file to process:{ files: function (subpath) { // return true if the file wanna pack } }packAsync -
boolean|Object|Function:optionalpack the page async require module (the sync dependency modules of the async module will be packed to this async module), by defaultfalse. If exist multi async modules, will all be packed to one module file. The pack option see the followingbundlesoptions. If page files are packed differently, you can passFunctionto custom:{ packAsync: { // the option is the same with `bundles` }, // custom the different pack strategies of page files packAsync: function (file) { if (file.indexOf('templates/common/script.tpl') !== -1) { return { packId: 'common' }; } return { // exclude the modules that are packed to `common` pack file files: ['!::common'], // filter the async module that is not to be packed. filterAsyncModule: function (id) { return id !== 'src/common/data.js'; } } } }packDepStyle -
boolean|Object|Function:optionalpack the dependent style resource of entry module. The pack target file by default is the last linked style file of the page if existed. The detail usage is the same as thepackAsync.extractVendor -
boolean|Object|Function:optionalextract the dependent vendor js modules of the entry module. The pack target file by default is${page_file_path_basename_notextname}${md5(page_file_path, 8)}_vendor.js. If you want to pack all page dependent vendor files to one file, you can specify the packtargetfile option. The detail usage is the same as thepackAsync.packCss -
boolean|Object|Function:optionalpack all linking style files as one file, by defaultfalse. The pack targe file by default is${page_file_path_notextname}_aio.css. The position of pack file linked is determined by the position<!--STYLE_PLACEHOLDER-->placeholder.{ target: function (defaultPackFile, pageFile) { return '<your custom pack target file>'; } }packJs -
boolean|Object|Function:optionalpack all linking script files as one file, by defaultfalse. The pack targe file by default is${page_file_path_notextname}_aio.js. The position of the packed file is similar topackCss, here using<!--SCRIPT_PLACEHOLDER-->placeholder.
bundles -
Array.<Object>:optionaldefine the bundles to pack, the bundle item option:files -
Array|Function: define the files to pack usinggloborregexp. Specifically, support the pack file reference syntax using::<packId>, when you wanna to exclude other pack files.target -
string: define the pack target filepreLoad -
boolean|Array:optionalwhether sync pre load the pack file, by defaultfalse, only supportjsandcsspack file. You can specify which page file will sync pre load the packed file, by default all page files, the output position is determined by theplaceholderposition of page file. If not placeholder is found, will auto insert placeholder by some rules, see below.{ files: ['/dep/**.js'], target: 'src/dep-all.js', preLoad: 'index.html' }packOrder -
number:optionaldefine the sync load order, the smaller the number is, the load order has higher priorities. In addition, you can using thepackOrderfile attribute to determine the pack priority.fis.match('src/common/css/base.css', { packOrder: -1 });packId -
string:optionaldefine the pack id, which can be referred by other pack items.packDeps -
boolean:optionalwhehter pack the dependence files of the packed files, by defaultfalse.
outputNotPackPathMap -
boolean:optionalwhether output the path map information of Js module files that are not packed, by defaultfalseamdConfig -
Object|Function:optionalcustom the output module config information, the configure will be merged with the definedpackage.json. And you can rewrite the configure by passing the function.inlineResourceConfig -
boolean:optionalwhether inline therequire.configconfigure information, by defaultfalse. The inline position is determined by the placeholder<!--RESOURCECONFIG_PLACEHOLDER-->position in the page file.resourceConfigFile -
Function:optionalby default therequire.configoutput file path is${page_file_path_notextname}_config.js, you can custom the output config file base on this option.autoInsertPlaceholder -
boolean: whether auto insert the fllowing placeholders when not found in the page files, by defaulttrue.scriptPlaceholder -
string: the script placeholder used to define the position to insert script, by default is<!--SCRIPT_PLACEHOLDER-->.stylePlaceholder -
string: the style placeholder used to define the position to insert link style, by default is<!--STYLE_PLACEHOLDER-->.resourceConfigPlaceholder -
string: therequire.configplaceholder used to define the position to inlinerequire.configinformation, by default is<!--RESOURCECONFIG_PLACEHOLDER-->.preprocessor -
Function:optional: before pack the files, you can do some work using this option.preprocessor: function (ret, context) { // do something... }
