mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 14:12:26 -05:00 
			
		
		
		
	[chore] Bundler restructure (#880)
* re-structure bundler, settings panel files * add more info logging * tidy up CSS syntax errors * split into lib/ files * livereloading server * fix factor function for production builds * remove testing console.log * default to production env, saves 300kb bundle size
This commit is contained in:
		
					parent
					
						
							
								56f53a2a6f
							
						
					
				
			
			
				commit
				
					
						5249294a16
					
				
			
		
					 40 changed files with 503 additions and 434 deletions
				
			
		|  | @ -22,55 +22,61 @@ const fs = require("fs"); | |||
| const path = require("path"); | ||||
| 
 | ||||
| const {Writable} = require("stream"); | ||||
| const {out} = require("../index.js"); | ||||
| const out = require("./output-path"); | ||||
| 
 | ||||
| const fromRegex = /\/\* from (.+?) \*\//; | ||||
| module.exports = function splitCSS() { | ||||
| 	let chunks = []; | ||||
| 	return new Writable({ | ||||
| 		write: function(chunk, encoding, next) { | ||||
| 			chunks.push(chunk); | ||||
| 			next(); | ||||
| 		}, | ||||
| 		final: function() { | ||||
| 			let stream = chunks.join(""); | ||||
| 			let input; | ||||
| 			let content = []; | ||||
| module.exports = function splitCSS(outputEmitter) { | ||||
| 	return function() { | ||||
| 		let chunks = []; | ||||
| 		return new Writable({ | ||||
| 			write: function(chunk, encoding, next) { | ||||
| 				chunks.push(chunk); | ||||
| 				next(); | ||||
| 			}, | ||||
| 
 | ||||
| 			function write() { | ||||
| 				if (content.length != 0) { | ||||
| 					if (input == undefined) { | ||||
| 						throw new Error("Got CSS content without filename, can't output: ", content); | ||||
| 					} else { | ||||
| 						console.log("writing to", out(input)); | ||||
| 						fs.writeFileSync(out(input), content.join("\n")); | ||||
| 					} | ||||
| 					content = []; | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			const cssDir = path.join(__dirname, "../css"); | ||||
| 
 | ||||
| 			stream.split("\n").forEach((line) => { | ||||
| 				if (line.startsWith("/* from")) { | ||||
| 					let found = fromRegex.exec(line); | ||||
| 					if (found != null) { | ||||
| 						write(); | ||||
| 
 | ||||
| 						let parts = path.parse(found[1]); | ||||
| 						if (path.relative(cssDir, path.join(process.cwd(), parts.dir)) == "") { | ||||
| 							input = parts.base; | ||||
| 			final: function() { | ||||
| 				let stream = chunks.join(""); | ||||
| 				let input; | ||||
| 				let content = []; | ||||
| 	 | ||||
| 				function write() { | ||||
| 					if (content.length != 0) { | ||||
| 						if (input == undefined) { | ||||
| 							if (content[0].length != 0) { | ||||
| 								throw new Error("Got CSS content without filename, can't output: ", content); | ||||
| 							} | ||||
| 						} else { | ||||
| 							// prefix filename with path
 | ||||
| 							let relative = path.relative(path.join(__dirname, "../"), path.join(process.cwd(), found[1])); | ||||
| 							input = relative.replace(/\//g, "-"); | ||||
| 							outputEmitter.emit("update", {type: "CSS", updates: [input]}); | ||||
| 							fs.writeFileSync(out(input), content.join("\n")); | ||||
| 						} | ||||
| 						content = []; | ||||
| 					} | ||||
| 				} else { | ||||
| 					content.push(line); | ||||
| 				} | ||||
| 			}); | ||||
| 			write(); | ||||
| 		} | ||||
| 	}); | ||||
| 	 | ||||
| 				const cssDir = path.join(__dirname, "../css"); | ||||
| 	 | ||||
| 				stream.split("\n").forEach((line) => { | ||||
| 					if (line.startsWith("/* from")) { | ||||
| 						let found = fromRegex.exec(line); | ||||
| 						if (found != null) { | ||||
| 							write(); | ||||
| 	 | ||||
| 							let parts = path.parse(found[1]); | ||||
| 							if (path.relative(cssDir, path.join(process.cwd(), parts.dir)) == "") { | ||||
| 								input = parts.base; | ||||
| 							} else { | ||||
| 								// prefix filename with path
 | ||||
| 								let relative = path.relative(path.join(__dirname, "../"), path.join(process.cwd(), found[1])); | ||||
| 								input = relative.replace(/\//g, "-"); | ||||
| 							} | ||||
| 						} | ||||
| 					} else { | ||||
| 						content.push(line); | ||||
| 					} | ||||
| 				}); | ||||
| 
 | ||||
| 				write(); | ||||
| 			} | ||||
| 		}); | ||||
| 	}; | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue