Skip to content

Instantly share code, notes, and snippets.

View ScriptedAlchemy's full-sized avatar
🎯
Focusing

Zack Jackson ScriptedAlchemy

🎯
Focusing
View GitHub Profile
@ScriptedAlchemy
ScriptedAlchemy / Index.js
Last active December 9, 2019 00:40
Module plugin
const path = require('path');
const VirtualStats = require('./virtual-stats');
class SyntheticPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
const moduleName = this.options.moduleName;
@ScriptedAlchemy
ScriptedAlchemy / Index.js
Last active November 28, 2019 04:22
Modifying tree-shaking module by module
if (moduleSource?.indexOf('externalize') > -1 || false) {
module.buildMeta = mergeDeep(module.buildMeta, { isExternalized: true });
// add exports back to usedExports, prevents tree shaking on module
Object.assign(module, { usedExports: module?.buildMeta?.providedExports || true });
try {
// look at refactoring this to use buildMeta not mutate id
module.id = moduleSource.match(/\/\*\s*externalize\s*:\s*(\S+)\s*\*\//)[1];
externalModules[module.id] = {};
@ScriptedAlchemy
ScriptedAlchemy / idea.vmoptions
Created November 26, 2019 22:23
improved perf vmoptions
-Xms1024m
-Xmx3072m
-Xss64m
-XX:ReservedCodeCacheSize=512m
-XX:+UseCompressedOops
-XX:NewRatio=2
-Dfile.encoding=UTF-8
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=250
-XX:NewSize=512m
@ScriptedAlchemy
ScriptedAlchemy / idea.propertie
Last active October 21, 2023 23:21
custom IntelliJ IDEA properties
# custom IntelliJ IDEA properties
editor.zero.latency.typing=true
idea.max.intellisense.filesize=3500
idea.cycle.buffer.size=2048
@ScriptedAlchemy
ScriptedAlchemy / Index.js
Last active November 25, 2019 00:47
Export used in unknown ways
compiler.hooks.thisCompilation.tap(
"FlagEntryExportAsUsedPlugin",
compilation => {
const moduleGraph = compilation.moduleGraph;
compilation.hooks.seal.tap("FlagEntryExportAsUsedPlugin", () => {
for (const deps of compilation.entryDependencies.values()) {
for (const dep of deps) {
const module = moduleGraph.getModule(dep);
if (module) {
const exportsInfo = moduleGraph.getExportsInfo(module);
@ScriptedAlchemy
ScriptedAlchemy / App1.js
Created November 24, 2019 23:38
Tree-shaking drops interleaved modules if not used
import React from 'react'
import Nav from './components/Menu' //Didnt use {MobileNav}, will be tree shaken
export default class App extends React {
render(){
return (<Nav>)
}
}
@ScriptedAlchemy
ScriptedAlchemy / Index.js
Last active November 25, 2019 00:49
Emitting a manifest map with dependencies
let files = compilation.chunks.reduce((files, chunk) => chunk.files.reduce((files, path) => {
let name = chunk.name ? chunk.name : null;
const dependencyChains = {};
if (name) {
name = `${name}.${this.getFileType(path)}`;
} else {
// For nameless chunks, just map the files directly.
name = path;
}
// check if the current chunk exists in externalModules, an object that is keeping track of keys
@ScriptedAlchemy
ScriptedAlchemy / EnteryManifest.js
Last active November 25, 2019 00:49
Entry Manifest with interleaved dependencies
if(!window.entryManifest) {window.entryManifest = {}};
window.entryManifest["some-namespace"] = {
"commons.js": {
"path": "static/chunks/commons.7343b2658e7f703389c2.js",
"dependencies": null,
"isInitial": true
},
"static/runtime/webpack.js.js": {
"path": "static/runtime/webpack-035ac2b14bde147cb4a8.js",
@ScriptedAlchemy
ScriptedAlchemy / EntryManifest.js
Last active November 25, 2019 00:49
Interleaved Manifest
if(!window.entryManifest) {window.entryManifest = {}};
window.entryManifest["some-namespace"] = {
"commons.js": {
"path": "static/chunks/commons.7343b2658e7f703389c2.js",
"isInitial": true
},
"static/runtime/webpack.js.js": {
"path": "static/runtime/webpack-035ac2b14bde147cb4a8.js",
"isInitial": true
@ScriptedAlchemy
ScriptedAlchemy / Index.js
Last active November 25, 2019 00:49
[contenthash] for webpack module ids
const createHash = require('webpack/lib/util/createHash');
const usedIds = new Set();
compilation.hooks.beforeModuleIds.tap('URLImportPlugin', (modules) => {
for (const module of modules) {
// if the module has an id, and its got a path to a real file
if (module.id === null && module.resource) {
const hash = createHash(this.opts.hashFunction || 'md4');
// grab the resource path, without any loader queries