{"_id":"rollup-plugin-dynamic-import-variables","_rev":"366275","name":"rollup-plugin-dynamic-import-variables","description":"Rollup plugin for resolving dynamic imports containing variables.","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"larsdenbakker","email":""}],"time":{"modified":"2021-07-19T07:28:31.000Z","created":"2020-05-01T10:59:21.684Z","1.1.0":"2020-07-13T11:27:34.991Z","1.0.2":"2020-06-18T14:37:20.792Z","1.0.1":"2020-05-11T06:55:18.037Z","1.0.0":"2020-05-01T10:59:21.684Z"},"users":{},"author":"","repository":{"type":"git","url":"git+https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables.git"},"versions":{"1.1.0":{"name":"rollup-plugin-dynamic-import-variables","version":"1.1.0","description":"Rollup plugin for resolving dynamic imports containing variables.","main":"index.js","dependencies":{"@rollup/pluginutils":"^3.0.9","estree-walker":"^2.0.1","globby":"^11.0.0","magic-string":"^0.25.7"},"devDependencies":{"acorn":"^7.1.1","acorn-dynamic-import":"^4.0.0","ava":"^2.4.0","prettier":"^2.0.5","rollup":"^2.7.5"},"scripts":{"format":"prettier \"src/**/*.{js,jsx,css,md}\" \"package.json\" --write && npm run format:index","test":"ava"},"prettier":{"singleQuote":true},"repository":{"type":"git","url":"git+https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables.git"},"author":"","license":"MIT","bugs":{"url":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables/issues"},"ava":{"files":["!**/fixtures/**","!**/helpers/**"]},"homepage":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables#readme","gitHead":"252c00998ca1c252400dd273af8c82cf83619797","_id":"rollup-plugin-dynamic-import-variables@1.1.0","_nodeVersion":"14.1.0","_npmVersion":"6.14.5","dist":{"shasum":"4981d38907a471b35234398a09047bef47a2006a","size":8527,"noattachment":false,"key":"/rollup-plugin-dynamic-import-variables/-/rollup-plugin-dynamic-import-variables-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rollup-plugin-dynamic-import-variables/download/rollup-plugin-dynamic-import-variables-1.1.0.tgz"},"maintainers":[{"name":"larsdenbakker","email":""}],"_npmUser":{"name":"larsdenbakker","email":"larsdenbakker@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-plugin-dynamic-import-variables_1.1.0_1594639654860_0.8654125661537899"},"_hasShrinkwrap":false,"publish_time":1594639654991,"_cnpm_publish_time":1594639654991},"1.0.2":{"name":"rollup-plugin-dynamic-import-variables","version":"1.0.2","description":"Rollup plugin for resolving dynamic imports containing variables.","main":"index.js","dependencies":{"@rollup/pluginutils":"^3.0.9","estree-walker":"^2.0.1","globby":"^11.0.0","magic-string":"^0.25.7"},"devDependencies":{"acorn":"^7.1.1","acorn-dynamic-import":"^4.0.0","ava":"^2.4.0","prettier":"^2.0.5","rollup":"^2.7.5"},"scripts":{"format":"prettier \"src/**/*.{js,jsx,css,md}\" \"package.json\" --write && npm run format:index","test":"ava"},"prettier":{"singleQuote":true},"repository":{"type":"git","url":"git+https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables.git"},"author":"","license":"MIT","bugs":{"url":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables/issues"},"ava":{"files":["!**/fixtures/**","!**/helpers/**"]},"homepage":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables#readme","gitHead":"0ce1964062d5ce6c61450dac1672537ac38f236c","_id":"rollup-plugin-dynamic-import-variables@1.0.2","_nodeVersion":"14.1.0","_npmVersion":"6.14.4","dist":{"shasum":"13328bd7c78f6dd1672f8eddb200d1b78b555f36","size":8360,"noattachment":false,"key":"/rollup-plugin-dynamic-import-variables/-/rollup-plugin-dynamic-import-variables-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/rollup-plugin-dynamic-import-variables/download/rollup-plugin-dynamic-import-variables-1.0.2.tgz"},"maintainers":[{"name":"larsdenbakker","email":""}],"_npmUser":{"name":"larsdenbakker","email":"larsdenbakker@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-plugin-dynamic-import-variables_1.0.2_1592491040638_0.9925571812116027"},"_hasShrinkwrap":false,"publish_time":1592491040792,"_cnpm_publish_time":1592491040792},"1.0.1":{"name":"rollup-plugin-dynamic-import-variables","version":"1.0.1","description":"Rollup plugin for resolving dynamic imports containing variables.","main":"index.js","dependencies":{"@rollup/pluginutils":"^3.0.9","estree-walker":"^2.0.1","globby":"^11.0.0","magic-string":"^0.25.7"},"devDependencies":{"acorn":"^7.1.1","acorn-dynamic-import":"^4.0.0","ava":"^2.4.0","prettier":"^2.0.5","rollup":"^2.7.5"},"scripts":{"format":"prettier \"src/**/*.{js,jsx,css,md}\" \"package.json\" --write && npm run format:index","test":"ava"},"prettier":{"singleQuote":true},"repository":{"type":"git","url":"git+https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables.git"},"author":"","license":"MIT","bugs":{"url":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables/issues"},"ava":{"files":["!**/fixtures/**","!**/helpers/**"]},"homepage":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables#readme","gitHead":"669f55fbefd2639d3ca220dc1bba82ccfa725d48","_id":"rollup-plugin-dynamic-import-variables@1.0.1","_nodeVersion":"14.1.0","_npmVersion":"6.14.4","dist":{"shasum":"1b17449ceba881a11277a4bd156765928e92fb51","size":8217,"noattachment":false,"key":"/rollup-plugin-dynamic-import-variables/-/rollup-plugin-dynamic-import-variables-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/rollup-plugin-dynamic-import-variables/download/rollup-plugin-dynamic-import-variables-1.0.1.tgz"},"maintainers":[{"name":"larsdenbakker","email":""}],"_npmUser":{"name":"larsdenbakker","email":"larsdenbakker@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-plugin-dynamic-import-variables_1.0.1_1589180117929_0.84871145228127"},"_hasShrinkwrap":false,"publish_time":1589180118037,"_cnpm_publish_time":1589180118037},"1.0.0":{"name":"rollup-plugin-dynamic-import-variables","version":"1.0.0","description":"Rollup plugin for resolving dynamic imports containing variables.","main":"index.js","dependencies":{"@rollup/pluginutils":"^3.0.9","estree-walker":"^2.0.1","globby":"^11.0.0","magic-string":"^0.25.7"},"devDependencies":{"acorn":"^7.1.1","acorn-dynamic-import":"^4.0.0","ava":"^2.4.0","prettier":"^2.0.5","rollup":"^2.7.5"},"scripts":{"format":"prettier \"src/**/*.{js,jsx,css,md}\" \"package.json\" --write && npm run format:index","test":"ava"},"prettier":{"singleQuote":true},"repository":{"type":"git","url":"git+https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables.git"},"author":"","license":"MIT","bugs":{"url":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables/issues"},"ava":{"files":["!**/fixtures/**","!**/helpers/**"]},"homepage":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables#readme","gitHead":"e12d566364bcd0f13d55d2d717d85c0c4c3bffb0","_id":"rollup-plugin-dynamic-import-variables@1.0.0","_nodeVersion":"10.19.0","_npmVersion":"6.13.4","dist":{"shasum":"cd1838ffce2d592a86962787e5ed026e7e89f8c0","size":8200,"noattachment":false,"key":"/rollup-plugin-dynamic-import-variables/-/rollup-plugin-dynamic-import-variables-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rollup-plugin-dynamic-import-variables/download/rollup-plugin-dynamic-import-variables-1.0.0.tgz"},"maintainers":[{"name":"larsdenbakker","email":""}],"_npmUser":{"name":"larsdenbakker","email":"larsdenbakker@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-plugin-dynamic-import-variables_1.0.0_1588330761580_0.8955402481258252"},"_hasShrinkwrap":false,"publish_time":1588330761684,"_cnpm_publish_time":1588330761684}},"readme":"# Rollup plugin dynamic import variables\n\nPlugin to support variables in dynamic imports in Rollup.\n\nTurns:\n\n```js\nfunction importLocale(locale) {\n  return import(`./locales/${locale}.js`);\n}\n```\n\nInto:\n\n```js\nfunction __variableDynamicImportRuntime__(path) {\n  switch (path) {\n    case './locales/en-GB.js':\n      return import('./locales/en-GB.js');\n    case './locales/en-US.js':\n      return import('./locales/en-US.js');\n    case './locales/nl-NL.js':\n      return import('./locales/nl-NL.js');\n    default:\n      throw new Error('Unknown variable dynamic import: ' + path);\n  }\n}\n\nfunction importLocale(locale) {\n  return __variableDynamicImportRuntime__(`./locales/${locale}.js`);\n}\n```\n\n## Usage\n\n```js\nimport dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';\n\nexport default {\n  plugins: [\n    dynamicImportVariables({\n      // options\n    }),\n  ],\n};\n```\n\n### Options\n\n#### include\n\nFiles to include in this plugin (default all).\n\n#### exclude\n\nFiles to exclude in this plugin (default none).\n\n#### warnOnError\n\nBy default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched.\n\n## How it works\n\nWhen a dynamic import contains a concatenated string, the variables of the string are replaced with a glob pattern. This glob pattern is evaluated during the build, and any files found are added to the rollup bundle. At runtime, the correct import is returned for the full concatenated string.\n\nSome example patterns and the glob they produce:\n\n```js\n`./locales/${locale}.js` -> './locales/*.js'\n```\n\n```js\n`./${folder}/${name}.js` -> './*/*.js'\n```\n\n```js\n`./module-${name}.js` -> './module-*.js'\n```\n\n```js\n`./modules-${name}/index.js` -> './modules-*/index.js'\n```\n\n```js\n'./locales/' + locale + '.js' -> './locales/*.js'\n```\n\n```js\n'./locales/' + locale + foo + bar '.js' -> './locales/*.js'\n```\n\n```js\n'./locales/' + `${locale}.js` -> './locales/*.js'\n```\n\n```js\n'./locales/' + `${foo + bar}.js` -> './locales/*.js'\n```\n\n## Limitations\n\nTo know what to inject in the rollup bundle, we have to be able to do some static analysis on the code and make some assumptions about the possible imports. For example, if you use just a variable you could in theory import anything from your entire file system.\n\n```js\nfunction importModule(path) {\n  // who knows what will be imported here?\n  return import(path);\n}\n```\n\nTo help static analysis, and to avoid possible foot guns, we are limited to a couple of rules:\n\n### Imports must start with `./` or `../`.\n\nAll imports must start relative to the importing file. The import should not start with a variable, an absolute path or a bare import:\n\n```js\n// Not allowed\nimport(bar);\nimport(`${bar}.js`);\nimport(`/foo/${bar}.js`);\nimport(`some-library/${bar}.js`);\n```\n\n### Imports must end with a file extension\n\nA folder may contain files you don't intend to import. We, therefore, require imports to end with a file extension in the static parts of the import.\n\n```js\n// Not allowed\nimport(`./foo/${bar}`);\n// allowed\nimport(`./foo/${bar}.js`);\n```\n\n### Imports to your own directory must specify a filename pattern\n\nIf you import your own directory you likely end up with files you did not intend to import, including your own module. It is therefore required to give a more specific filename pattern:\n\n```js\n// not allowed\nimport(`./${foo}.js`);\n// allowed\nimport(`./module-${foo}.js`);\n```\n\n### Globs only go one level deep\n\nWhen generating globs, each variable in the string is converted to a glob `*` with a maximum of one star per directory depth. This avoids unintentionally adding files from many directories to your import.\n\nIn the example below this generates `./foo/*/*.js` and not `./foo/**/*.js`.\n\n```js\nimport(`./foo/${x}${y}/${z}.js`);\n```\n","_attachments":{},"homepage":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables#readme","bugs":{"url":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables/issues"},"license":"MIT"}