{"id":15674904,"url":"https://github.com/tuchk4/requirejs-codemirror","last_synced_at":"2025-05-06T23:29:56.505Z","repository":{"id":15472299,"uuid":"18205698","full_name":"tuchk4/requirejs-codemirror","owner":"tuchk4","description":"Load codemirror with needed modes and appending codemirror's css only when needed","archived":false,"fork":false,"pushed_at":"2016-04-13T10:10:12.000Z","size":176,"stargazers_count":14,"open_issues_count":1,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T16:17:21.846Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuchk4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-28T08:32:04.000Z","updated_at":"2017-08-25T03:57:45.000Z","dependencies_parsed_at":"2022-09-05T15:51:40.596Z","dependency_job_id":null,"html_url":"https://github.com/tuchk4/requirejs-codemirror","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Frequirejs-codemirror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Frequirejs-codemirror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Frequirejs-codemirror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Frequirejs-codemirror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuchk4","download_url":"https://codeload.github.com/tuchk4/requirejs-codemirror/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252786850,"owners_count":21804158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T15:52:54.786Z","updated_at":"2025-05-06T23:29:56.458Z","avatar_url":"https://github.com/tuchk4.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Requirejs and CodeMirror\n\n#### 1. Existing problem\n\nWhen you need to use CodeMirror:\n\n- you need to load codemirror\n- you need to append codemirror's css file\n- you need to load needed codemirror's modes\n\nThis is not hard to set path to CodeMirror lib at requriejs.config :) And you will be able to load it with:\n\n```javascript\nrequire('code-mirror');\n```\n\nAnd all will be ok. But you also need to append CSS file (and this CSS should be only at pages where codemirror is using). This is also not a big problem. A lot of ways how it could be appened.\n\nBut main problem - in loading CodeMirror modes.\n\nhttp://codemirror.net/2/demo/loadmode.html\n\nDefault application structure:\n\n    |-app/\n    |   |\n    |   |-src/\n    |   |-boot.js\n    |\n    |-bower_components/\n\n\n- **app/** - directory with application scripts\n- **boot.js** - config for require js (entry point). \n- **bower_components/** - directory with downloaded bower components xD\n\nIn boot.js set **baseUrl** key in config that value is usually set to app/ directory.\nSo if you want to require bower_component in boot.js file you neeed to set path to upper directory\n\n```javascript\nrequire('../bower_components/module/module-script');\n```\n\nAnd you can not set paths to CodeMirror modes at requirejs.config because:\n\nCodeMirror check if requriejs is used, and if so - CodeMirror will use it. And If you descrive path to CodeMirror's mode at requriejs.config -\n**require** function inside modes scitpts will have relative path from **boot.js** and it will be able to load other dependencies because paths will be wrong.\n\nAnd it will be not beautiful to require bower_components inside scripts when you should write full path to component. And this path should be relative from current script. Something like ../../../../bower_components/... that is not beautiful :)\n\nAnd same problem with CodeMirror.autoLoadMode\n\n#### 2. RequireJS plugin for CodeMirror\n\nUsage:\n\n```javascript\n// will require CodeMirror and inlcude CSS file\nvar CodeMirror = require('code-mirror!@');\n\n// will require CodeMirror, inlcude CSS file and load htmlmixed mode\nvar CodeMirror = require('code-mirror!htmlmixed');\n\n// will require CodeMirror, inlcude CSS file and load htmlmixed and php modes\nvar CodeMirror = require('code-mirror!htmlmixed|php');\n\n// will require CodeMirror, inlcude CSS file and load htmlmixed and php modes\n// and ambiance, eclipse and monokai themes.\nvar CodeMirror = require('code-mirror!htmlmixed|php:ambiance|eclipse|monokai');\n```\n\nAnd plugin should be configured at requirejs.conf:\n\n```javascript\nrequirejs.config({\n cm: {\n \t// baseUrl to CodeMirror dir\n    baseUrl: '../bower_components/CodeMirror/',\n    // path to CodeMirror lib\n    path: 'lib/codemirror',\n    // path to CodeMirror css file\n    css: '/path/to/code-mirror/css/file',\n    // define themes\n    themes: {\n        monokai: '/path/to/theme/monokai.css',\n        ambiance: '/path/to/theme/ambiance.css',\n        eclipse: '/path/to/theme/eclipse.css'\n    },\n    modes: {\n      // modes dir structure\n      path: 'mode/{mode}/{mode}'\n    }\n  }\n});\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuchk4%2Frequirejs-codemirror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuchk4%2Frequirejs-codemirror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuchk4%2Frequirejs-codemirror/lists"}