Skip to content

Instantly share code, notes, and snippets.

@SigurdMW
SigurdMW / webpack.config.js
Created May 8, 2017 10:31
Simple Webpack + babel setup
// remember to run first: npm i --save-dev webpack path babel-core babel-preset-es2015 babel-loader
/* Simplistic .babelrc file:
{
"presets": ["es2015"]
}
*/
var path = require('path');
@SigurdMW
SigurdMW / standard-gulp-setup
Last active May 23, 2017 11:55
A simple and standard setup of Gulp
// filemane: gulpfile.js
// ruby must be installed, then run gem install sass
// npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del gulp-babel babel-preset-env --save-dev
// also need to get jshint to work: .jshintrc
/*
UPDATE: without ruby: https://github.com/dlmanning/gulp-sass
ex:
@SigurdMW
SigurdMW / no-jquery.js
Created May 29, 2017 08:08
helpers to avoid using jquery. Focus on browser compat
// classlist helper for better browser compat
var hasClass = function(el, className){
if (el.classList){
return el.classList.contains(className);
} else {
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
}
}
// classlist helper for better browser compat
var hasClass = function (el, className) {
if (el.classList) {
return el.classList.contains(className);
} else {
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
}
}
// helper for setting multiple attributes to same element
@SigurdMW
SigurdMW / gulpfile.js
Last active May 2, 2023 12:46
gulp setup with browserify and babelify
// npm install --save-dev gulp babelify browserify babel-preset-es2015 gulp-connect vinyl-source-stream vinyl-buffer gulp-uglify gulp-sourcemaps
/*
folder structure:
build
src/js/index.js
static/index.html
package.json
gulpfile.js
*/
@SigurdMW
SigurdMW / package.json
Last active October 19, 2019 09:55
Webpack config for Epi Server. Handles .scss, .css, .js, font-files, images (in .js/.scss/.css). Autoprefix and minifying is included
{
"name": "skuld-frontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "backstop test",
"approve-tests": "backstop approve",
"build": "set NODE_ENV=production && webpack -p",
"watch": "webpack --cache=false --watch"
@SigurdMW
SigurdMW / _Root.cshtml
Created August 31, 2017 13:25
Adding bundles in EpiServer
...
@Styles.Render("~/Bundles/CSS")
...
@Scripts.Render("~/Bundles/JS")
...
@SigurdMW
SigurdMW / w3cjs.js
Last active August 31, 2017 20:26
Start of setup of w3cjs for automated markup validation service.
// npm install --save-dev w3cjs
var w3cjs = require('w3cjs');
var timer = 0;
var takeTime = setInterval(function() {
timer = timer + 1;
}, 1);
const validationService = (target) => {
return new Promise((resolve, reject) => {
@SigurdMW
SigurdMW / MegaMenu.js
Last active September 11, 2017 07:25
Accessible and super light weight Mega Menu. Features: one sublevel mega menu (for now), close on esc, automatic overlay with close on click, close submenu when last link loses focus.
class MegaMenu {
constructor() {
this.options = {
selector: "mega-menu",
trigger: "menu-link--has-children"
}
this.menuOpen = false;
this.documentBody = document.body;
this.megaMenu = document.querySelector("." + this.options.selector);
@SigurdMW
SigurdMW / polyfills.js
Created September 7, 2017 15:28
polyfills for ie 10/11 for findIndex, and forEach on nodeLists
function polyfill() {
// allow using el.querySelectorAll(...).forEach(...) for looping through nodeLists
if (!NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
// allow using [].findIndex(...) in all browsers
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex