From dd8333173c254d60c4d64ea8a49ec0e7de363d8f Mon Sep 17 00:00:00 2001
From: Florent Masson
Date: Wed, 26 Jan 2022 11:34:22 +0100
Subject: [PATCH 1/5] Allow library to be inserted in HEAD tag and lazily
loaded https://github.com/R-TEK/colr_pickr/issues/5
---
gulpfile.js | 5 +++++
package.json | 2 ++
src/sample.html | 4 +++-
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/gulpfile.js b/gulpfile.js
index 7077238..d4a056a 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -9,6 +9,7 @@ const concatJS = require('gulp-concat');
const uglifyJS = require('gulp-uglify-es').default;
const concatCSS = require('gulp-concat-css');
const uglifyCSS = require('gulp-uglifycss');
+const inject = require('gulp-inject-string');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
@@ -20,6 +21,8 @@ sass.compiler = require('node-sass');
gulp.task('devScripts', async function () {
gulp.src(['./src/js/setup.js', './src/js/*.js'])
.pipe(concatJS('colr_pickr.js'))
+ .pipe(inject.prepend('document.addEventListener("DOMContentLoaded", function () {'))
+ .pipe(inject.append('window.ColorPicker = ColorPicker;window.colorPickerComp = colorPickerComp;});'))
.pipe(gulp.dest('./build'));
});
@@ -44,6 +47,8 @@ gulp.task('productionScripts', async function () {
gulp.src(['./src/js/setup.js', './src/js/*.js'])
.pipe(concatJS('colr_pickr.min.js'))
.pipe(uglifyJS())
+ .pipe(inject.prepend('document.addEventListener("DOMContentLoaded", function () {'))
+ .pipe(inject.append('window.ColorPicker = ColorPicker;window.colorPickerComp = colorPickerComp;});'))
.pipe(gulp.dest('./build'));
});
diff --git a/package.json b/package.json
index b5afb24..4074fda 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"browser": "build/colr_pickr.min.js",
"license": "MIT",
"scripts": {
+ "devBuild": "gulp devBuild",
"build": "gulp productionBuild",
"doc": "jsdoc -c jsdoc.json",
"test": "echo \"Error: no test specified\" && exit 1"
@@ -49,6 +50,7 @@
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-concat-css": "^3.1.0",
+ "gulp-inject-string": "^1.1.2",
"gulp-markdown": "^5.0.1",
"gulp-rimraf": "^1.0.0",
"gulp-sass": "^4.1.0",
diff --git a/src/sample.html b/src/sample.html
index 02def23..e45c728 100644
--- a/src/sample.html
+++ b/src/sample.html
@@ -7,6 +7,7 @@
+
@@ -205,8 +206,8 @@ Color Selector
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu erat, accumsan
id imperdiet et, porttitor at sem. Pellentesque in ipsum id orci porta dapibus.
-