{"_id":"@amarajs/plugin-bundle","_rev":"2-d667e94d9b19f06209f760037b380b62","name":"@amarajs/plugin-bundle","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@amarajs/plugin-bundle","version":"0.1.0","description":"Server-side plugin to bundle folder contents into a single file using Rollup.","main":"dist/amara-plugin-bundle.js","umd:main":"dist/amara-plugin-bundle.umd.js","jsnext:main":"src/index.js","scripts":{"build":"npm-run-all -p rollup:* -p minify:*","rollup:cjs":"rollup -c rollup.config.js -i src/index.js -f cjs -o dist/amara-plugin-bundle.js","rollup:umd":"rollup -c rollup.config.js -i src/index.js -f umd -o dist/amara-plugin-bundle.umd.js -n AmaraBundle","minify:cjs":"uglifyjs dist/amara-plugin-bundle.js -cm toplevel -o dist/amara-plugin-bundle.min.js --source-map filename=dist/amara-plugin-bundle.min.js.map","minify:umd":"uglifyjs dist/amara-plugin-bundle.umd.js -cm toplevel -o dist/amara-plugin-bundle.umd.min.js --source-map filename=dist/amara-plugin-bundle.umd.min.js.map"},"keywords":["amarajs","server","plugin","bundle","rollup"],"author":{"name":"Dan Barnes","email":"amarajs.framework@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/amarajs/plugin-bundle.git"},"files":["src","dist"],"devDependencies":{"npm-run-all":"^4.1.2","rollup":"^0.57.1","rollup-plugin-buble":"^0.15.0","uglify-js":"^3.3.21"},"gitHead":"89b2fc9206a2b579646ec2f1f455728c5588c753","bugs":{"url":"https://github.com/amarajs/plugin-bundle/issues"},"homepage":"https://github.com/amarajs/plugin-bundle#readme","_id":"@amarajs/plugin-bundle@0.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"amarajs-dan","email":"amarajs.framework@gmail.com"},"dist":{"integrity":"sha512-blogcEt0U1mK1OoYVggl+nL+PKPW7ciVKskPZ4gx6m8nmG1JhdnIfWtn4RRRnOg5sdcvKSP+qnkDuzqkJoajpg==","shasum":"ed695e1dd881b02bfb35e700ee446d430e279754","tarball":"https://registry.npmjs.org/@amarajs/plugin-bundle/-/plugin-bundle-0.1.0.tgz","fileCount":10,"unpackedSize":25156,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBYXJzxIyszstSO/PNNZAUPzz4cQWMyGNQ1mfNO0Z8WHAiEAnhBptZVnrDyzQYTzBPGXb1EukPUV6Zt3wNPV9mdfopI="}]},"maintainers":[{"name":"amarajs-dan","email":"amarajs.framework@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/plugin-bundle_0.1.0_1523578535416_0.14252122130294276"},"_hasShrinkwrap":false}},"time":{"created":"2018-04-13T00:15:35.324Z","0.1.0":"2018-04-13T00:15:35.556Z","modified":"2022-04-04T13:43:42.440Z"},"maintainers":[{"name":"amarajs-dan","email":"amarajs.framework@gmail.com"}],"description":"Server-side plugin to bundle folder contents into a single file using Rollup.","homepage":"https://github.com/amarajs/plugin-bundle#readme","keywords":["amarajs","server","plugin","bundle","rollup"],"repository":{"type":"git","url":"git+https://github.com/amarajs/plugin-bundle.git"},"author":{"name":"Dan Barnes","email":"amarajs.framework@gmail.com"},"bugs":{"url":"https://github.com/amarajs/plugin-bundle/issues"},"license":"MIT","readme":"## [@amarajs/plugin-bundle](https://github.com/amarajs/plugin-bundle)\n\nPlugin middleware for AmaraJS to add server-side bundling of JS files using [Rollup](https://github.com/rollup/rollup).\n\n### Installation\n\n`npm install --save @amarajs/plugin-bundle`\n\n### Usage\n\n```javascript\nconst Amara = require('@amarajs/core');\nconst AmaraPluginBundle = require('@amarajs/plugin-bundle');\nconst AmaraPluginEngineServer = require('@amarajs/plugin-engine-server');\n\nconst amara = Amara([\n    AmaraPluginEngineServer(server),\n    AmaraPluginBundle(require('rollup'))\n]);\n```\n\n### Feature Type\n\nThe `@amarajs/plugin-bundle` middleware allows you to create features of type `\"bundle\"` and `\"transform\"`.\n\n#### Return Values\n\nFor `{type: \"bundle\"}` features, your apply function should return a [rollup configuration object](https://rollupjs.org/guide/en#core-functionality).\n\n```javascript\n// convert any requests for bundle/<folder>.js into\n// a bundle named <folder>.js, generated by transpiling\n// all files in the features/<folder> directory\n\nconst path = require('path');\nconst transpile = require('rollup-plugin-buble')\nconst multi = require('rollup-plugin-multi-entry');\nconst dir = path.resolve();\nconst invalid = /[^_a-z0-9]+/g;\n\namara.add({\n    type: 'bundle',\n    targets: ['GET /bundle/*.js'],\n    args: {\n        folder: ({target}) => {\n            const ext = path.extname(target.path);\n            const folder = target.path.split('/').pop();\n            return folder.replace(ext, '');\n        }\n    },\n    apply: ({folder}) => ({\n        input: `${dir}/features/${folder}/*.js`,\n        output: {\n            format: 'iife',\n            name: folder.replace(invalid, '_')\n        },\n        plugins: [\n            multi(),\n            transpile()\n        ]\n    })\n});\n```\n\nFor `{type: \"transform\"}` features, your apply function should return a function that accepts a string parameter (the code to transform) and returns the transformed string.\n\n```javascript\n// strip all lines with the word 'password' on them,\n// but only from JS files under the features folder\nconst rx = /^(.*?password.*?)$/mig;\namara.add({\n    type: 'transform',\n    targets: ['GET /features/**/*.js'],\n    apply: () => (code) => {\n        return code.replace(rx, '');\n    }\n});\n```\n\n### Applying Multiple Results to the Same Target\n\nIf multiple `{type: \"bundle\"}` features target the same request, the configuration objects will be merged, with later configurations winning over earlier configurations. Arrays will be concatenated and de-duplicated.\n\nIf multiple `{type: \"transform\"}` features target the same request, the functions will be invoked in the order added, with the results from the previous transformer being passed as input to the next transformer.\n\n### Customization\n\nYou must provide an instance of `rollup` to the plugin factory.\n\n### Contributing\n\nIf you have a feature request, please create a new issue so the community can discuss it.\n\nIf you find a defect, please submit a bug report that includes a working link to reproduce the problem (for example, using [this fiddle](https://jsfiddle.net/04f3v2x4/)). Of course, pull requests to fix open issues are always welcome!\n\n### License\n\nThe MIT License (MIT)\n\nCopyright (c) Dan Barnes\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md"}