├── .eslintrc.js ├── .gitignore ├── LICENSE ├── README.md ├── dist ├── core.js └── loaders.js ├── index.js ├── jest.config.js ├── loaders ├── index.js ├── react-loader.js ├── typescript-loader.js └── utils.js ├── package-lock.json ├── package.json └── tests ├── index.spec.js └── pages └── simple.html /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ENV: { 3 | jest: true, 4 | }, 5 | globals: { 6 | globalThis: true, 7 | page: true, 8 | }, 9 | extends: 'eslint-config-sprite', 10 | rules: { 11 | complexity: ['warn', 25], 12 | 'no-unused-vars': 'warn', 13 | 'no-restricted-globals': 'off', 14 | 'max-params': ['warn', 7], 15 | 'import/no-anonymous-default-export': 'off', 16 | 'no-console': 'warn', 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log* 3 | .nyc_*/ 4 | .dir-locals.el 5 | .DS_Store 6 | .test 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 稀土掘金 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ES inline module 2 | 3 | A simple way of loading inline es-modules on modern browser. 4 | 5 | ## Usage 6 | 7 | 1. Use `inlineImport` to dynamically import inline scripts. 8 | 9 | ```html 10 | 14 | 15 | 19 | ``` 20 | 21 | 2. Auto setup to insert importmap. Then you can use inline module as normal es-modules. 22 | 23 | ```html 24 | 28 | 29 | 33 | ``` 34 | 35 | **Note:inline-module script must be setup before all module scripts and after all inline-module scripts in this mode.** 36 | 37 | 3. Use setup and external importmap. 38 | 39 | ```html 40 | 47 | 51 | 52 | 58 | ``` 59 | 60 | ## v0.4+ Update 61 | 62 | 1. react & typescript loader 63 | 64 | ```html 65 | 72 | 95 | 96 | 97 | 98 |
99 | 105 | ``` 106 | -------------------------------------------------------------------------------- /dist/core.js: -------------------------------------------------------------------------------- 1 | (()=>{var d=window["inline-module-loaders"],l=document.currentScript||document.querySelector("script"),a={imports:{},scopes:{}},f=new Set;function y(t){return btoa(unescape(encodeURIComponent(t)))}function g(t){let n=new XMLHttpRequest;if(n.open("GET",t,!1),n.send(null),n.status===200)return n.responseText;throw new Error(n.statusText)}function S(t,n){let r=/^(\s*import\s+[\s\S]*?from\s*['"`])([\s\S]*?)(['"`])/img;return t.replace(r,(s,i,e,o)=>{let c=n[e];return c?`${i}${c}${o}`:`${i}${e}${o}`})}function b(t,n=!1,r={}){let s=t.textContent;if(t.hasAttribute("src")){let e=t.getAttribute("src");s=g(e),t.textContent=s}n&&(s=S(s,r));let i=t.getAttribute("loader");return i&&(i=i.split(/\s*>\s*/),s=i.reduce((e,o)=>{let{transform:c,imports:p}=d[o],{code:u,map:m}=c(e,{sourceMap:!0,filename:t.getAttribute("name")||t.id||"anonymous"});return m?e=`${u} 2 | 3 | //# sourceMappingURL=data:application/json;base64,${y(JSON.stringify(m))}`:e=u,Object.assign(r.imports,p),e},s)),$(s,"text/javascript")}function $(t,n="text/plain"){let r=new Blob([t],{type:n});return URL.createObjectURL(r)}function w(){let t=document.querySelectorAll('script[type="inline-module"]'),n={},r=[],s=document.querySelector('script[type="importmap"]');s&&console.warn('Cannot update importmap after 16 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | --------------------------------------------------------------------------------