Conditional build based on environment using Webpack

You can use the define plugin. I use it by doing something as simple as this in your webpack build file where env is the path to a file that exports an object of settings: // Webpack build config plugins: [ new webpack.DefinePlugin({ ENV: require(path.join(__dirname, ‘./path-to-env-files/’, env)) }) ] // Settings file located at `path-to-env-files/dev.js` … Read more

require file as string

If it’s for a (few) specific extension(s), you can add your own require.extensions handler: var fs = require(‘fs’); require.extensions[‘.txt’] = function (module, filename) { module.exports = fs.readFileSync(filename, ‘utf8’); }; var words = require(“./words.txt”); console.log(typeof words); // string Otherwise, you can mix fs.readFile with require.resolve: var fs = require(‘fs’); function readModuleFile(path, callback) { try { var … Read more

How can I use jQuery in Greasemonkey scripts in Google Chrome?

From “User Script Tip: Using jQuery – Erik Vold’s Blog” // ==UserScript== // @name jQuery For Chrome (A Cross Browser Example) // @namespace jQueryForChromeExample // @include * // @author Erik Vergobbi Vold & Tyler G. Hicks-Wright // @description This userscript is meant to be an example on how to use jQuery in a userscript on … Read more

How to deal with cyclic dependencies in Node.js

Try to set properties on module.exports, instead of replacing it completely. E.g., module.exports.instance = new ClassA() in a.js, module.exports.ClassB = ClassB in b.js. When you make circular module dependencies, the requiring module will get a reference to an incomplete module.exports from the required module, which you can add other properties latter on, but when you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)