diff --git a/package.json b/package.json index a41cddfd..17d94914 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,10 @@ "scripts": { "start": "npm run build -- --watch", "build": "npm run babel && npm run stencil --", - "stencil": "stencil build --docs-json dist/data/docs.json --esm --es5", + "stencil": "stencil build --docs-json dist/data/docs.json --esm --es5 && npm run rename && npm run renameDev", "babel": "mkdirp .build && babel src/helpers/index.js --out-file .build/index.js", + "rename": "renamer -f \"/^corporate-ui.js$/\" -r \"corporate-ui-stencil.js\" \"dist/*\"", + "renameDev": "renamer -f \"/^corporate-ui-dev.js$/\" -r \"corporate-ui.js\" \"dist/*\"", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", "lint-fix": "npm run lint -- --fix", "lint-debug": "npm run lint -- --debug", @@ -54,7 +56,8 @@ "mkdirp": "^0.5.1", "popper.js": "1.15.0", "puppeteer": "1.19.0", - "redux": "4.0.4" + "redux": "4.0.4", + "renamer": "1.1.4" }, "license": "MIT" } diff --git a/readme.md b/readme.md index 91874f7f..2e02f79d 100644 --- a/readme.md +++ b/readme.md @@ -52,10 +52,8 @@ Several options to add corporate-ui in the project: Add link to the script by adding the following to the head - **SUBJECT TO CHANGE!** - ``` - + ``` Replace `x` with [available releases](https://github.com/scania/corporate-ui/releases). diff --git a/src/helpers/cdn.js b/src/helpers/cdn.js new file mode 100644 index 00000000..b76986d6 --- /dev/null +++ b/src/helpers/cdn.js @@ -0,0 +1,16 @@ +(function(doc){ + var scriptElm = doc.scripts[doc.scripts.length - 1]; + + var parentScript = doc.querySelectorAll('script'); + + var parts = scriptElm.src.split('/'); + parts.pop(); + parts.push('corporate-ui'); + var url = parts.join('/'); + + scriptElm = doc.createElement('script'); + scriptElm.src = url + '/corporate-ui.js'; + + doc.head.insertBefore(scriptElm, parentScript[0]); + +})(document); \ No newline at end of file diff --git a/stencil.config.ts b/stencil.config.ts index 8d98fe7c..5dd36823 100644 --- a/stencil.config.ts +++ b/stencil.config.ts @@ -8,12 +8,13 @@ export const config: Config = { globalScript: 'src/global.ts', enableCache: false, hashFileNames: false, - devMode: true, + devMode: true, outputTargets: [ { type: 'dist', copy: [ - { src: '../.build/index.js', dest: 'index.js' } + { src: '../.build/index.js', dest: 'index.js' }, + { src: 'helpers/cdn.js', dest: '../corporate-ui-dev.js', warn:true }, ] }, {