{"id":15516481,"url":"https://github.com/hypervillain/babel-transform-config","last_synced_at":"2025-04-23T03:33:09.660Z","repository":{"id":42916875,"uuid":"248484318","full_name":"hypervillain/babel-transform-config","owner":"hypervillain","description":"Use Babel to transform a JS configuration files","archived":false,"fork":false,"pushed_at":"2023-01-05T16:35:21.000Z","size":135,"stargazers_count":9,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T21:41:24.421Z","etag":null,"topics":["babel","babel-plugin","gatsby","nextjs","nuxt"],"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/hypervillain.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":"2020-03-19T11:20:51.000Z","updated_at":"2021-07-09T19:26:29.000Z","dependencies_parsed_at":"2023-02-04T07:17:08.926Z","dependency_job_id":null,"html_url":"https://github.com/hypervillain/babel-transform-config","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/hypervillain%2Fbabel-transform-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypervillain%2Fbabel-transform-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypervillain%2Fbabel-transform-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypervillain%2Fbabel-transform-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypervillain","download_url":"https://codeload.github.com/hypervillain/babel-transform-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250365964,"owners_count":21418764,"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":["babel","babel-plugin","gatsby","nextjs","nuxt"],"created_at":"2024-10-02T10:08:04.890Z","updated_at":"2025-04-23T03:33:09.645Z","avatar_url":"https://github.com/hypervillain.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## babel-transform-config\nIf you ever wanted to update a Nuxt or Next config file programmatically.\n#### Readme: wip\nSimplest way to understand what it does:\n\n````bash\ngit clone https://github.com/hypervillain/babel-transform-config;\ncd babel-transform-config \u0026\u0026 npm install;\nnode examples/nuxt.simple.js\n````\nThis should display some info 👇\n\n##### 1/ previous code:\n\nThe actual `nuxt.config.js` file that was read from file.\nSomething like:\n```javascript\nexport default {\n  css: [],\n  modules: ['@org/my-nuxt-module'],\n  build: {\n    webpack : {}\n  },\n};\n````\n\n##### 2/ args passed :\nThe arguments that were passed to `babel-transform-config`.\nSomething like:\n```javascript\nconst args = {\n  css: ['path/to/file'],\n  modules: [\n    ['my-module', { config: true }]\n  ],\n  transpile: ['my-other-module']\n}\n// will be used like this:\n// transformConfig(code, 'nuxt', args)\n````\n\n##### 3/ the transpiled code :\nWhat you came for:\n```javascript\nexport default {\n  css: [\"path/to/file\"],\n  modules: ['@org/my-nuxt-module', [\"my-module\", {\n    \"config\": true\n  }]],\n  build: {\n    webpack: {},\n    transpile: [\"my-other-module\"]\n  }\n};\n````\n\n## Using the module\n\nThis package exports a `transformConfig` function that takes as arguments some code, a framework key, and key-value params that will help the module transform these arguments.\n\nFor example, these arguments:\n````javascript\nconst args = {\n    script: ['path/to/script-file.js']\n}\ntransformConfig(myNuxtConfig, 'nuxt', args)\n````\n\n`transformConfig` will try \u0026 match your script key and transform your arguments into:\n````javascript\ntransforms: [{\n    'head:script': {\n        action: 'create:merge',\n        value: ['path/to/script-file.js']\n    }\n],\n````\nThis will help the underlying Babel plugin perform the right actions, based on what it knows of your framework. The complete call:\n\n````javascript\nconst fs = require('fs')\nconst transformConfig = require('babel-transform-config')\n\nconst code = fs.readFileSync('path/to/config', 'utf8')\nconst args = { script: ['path/to/script-file.js'] }\n\nconst { code: updatedCode} = transformConfig(code, 'nuxt', args)\n\n// ⚠️ this is experimental, please log things first\nfs.writeFileSync('path/to/config', updatedCode, 'utf8')\n\n````\n\n## Direct transform / Babel plugin\n\nRight now, `transformConfig` only supports Nuxt framexwork. If you want to use things for yourself with another framework, you should use the lower-level transform method:\n\n```javascript\nconst { transform } = require('babel-transform-config')\n\nconst transforms = {\n  'head:script': { // create or replace export default { head: { script: [] }}\n    action: 'create:replace',\n    value: ['my/script.js']\n  },\n  'deleteMe': { // delete export default { deleteMe: ... }\n    action: 'delete'\n  },\n  'build:transpile': { // merges export default { babel: { transpile: arrayOrObject } }\n    action: 'merge',\n    value: ['path/to/file']\n  }\n}\nconst { code: updatedCode } = transform(yourCustomCode, transforms)\n\n`````\n\n👆 See `examples/transform`.\n\n\n#### Quick note\n\nATM you'll need to use ES2015 `export default` feature to use this plugin.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypervillain%2Fbabel-transform-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypervillain%2Fbabel-transform-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypervillain%2Fbabel-transform-config/lists"}