{"id":15061187,"url":"https://github.com/rrdelaney/bs-loader","last_synced_at":"2025-10-05T02:31:33.032Z","repository":{"id":57348507,"uuid":"83644665","full_name":"rrdelaney/bs-loader","owner":"rrdelaney","description":":radio: Bucklescript loader for Webpack and Jest","archived":true,"fork":false,"pushed_at":"2018-10-09T16:08:39.000Z","size":330,"stargazers_count":143,"open_issues_count":0,"forks_count":22,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T09:08:49.623Z","etag":null,"topics":["bucklescript","jest-transform","ocaml","reason","reasonml","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rrdelaney.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-02T06:48:50.000Z","updated_at":"2023-09-07T01:31:22.000Z","dependencies_parsed_at":"2022-08-31T18:02:58.913Z","dependency_job_id":null,"html_url":"https://github.com/rrdelaney/bs-loader","commit_stats":null,"previous_names":["reasonml-community/bs-loader"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrdelaney%2Fbs-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrdelaney%2Fbs-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrdelaney%2Fbs-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrdelaney%2Fbs-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rrdelaney","download_url":"https://codeload.github.com/rrdelaney/bs-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235356078,"owners_count":18976818,"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":["bucklescript","jest-transform","ocaml","reason","reasonml","webpack","webpack-loader"],"created_at":"2024-09-24T23:11:22.268Z","updated_at":"2025-10-05T02:31:27.685Z","avatar_url":"https://github.com/rrdelaney.png","language":"JavaScript","readme":"# bs-loader [![Build Status](https://travis-ci.org/reasonml-community/bs-loader.svg?branch=master)](https://travis-ci.org/reasonml-community/bs-loader)\n\u003e Bucklescript loader for Webpack\n\n---\n**This library is in maintanence mode. Instead of using bs-loader we recommend\nusing bsb' new in-source builds in conjunction with .bs.js extensions:**\n\n```json\n// bcsconfig.json\n{\n  \"package-specs\": {\n    \"module\": \"commonjs\",\n    \"in-source\": true\n  },\n  \"suffix\": \".bs.js\",\n}\n```\n\n---\nThis works with both Reason and OCaml files\n\n## Installation\n\n```\nnpm install bs-loader\n```\n\n## [Example](https://github.com/reasonml-community/bs-loader/blob/master/examples)\n\n## Setting up Bucklescript\n\nFirst install `bs-platform` into the project:\n\n```\n$ npm i -D bs-platform\n```\n\nCreate a `bsconfig.json` for Bucklescript:\n\n```json\n/* bsconfig.json */\n{\n  \"name\": \"hello\",\n  \"sources\": [\n    \"src\"\n  ],\n  \"bs-dependencies\": [\n    \"reason-react\"\n  ],\n  \"reason\": {\n    \"react-jsx\": 2\n  }\n}\n```\n\nWe will also need `reason-react`, and `bs-platform`. You can install `bs-platform` globally and\nuse `npm link` to the link the binary, or install `bs-platform` as a devDependency.\nYour `package.json` should look something like this:\n\n```json\n/* package.json */\n{\n  \"name\": \"reason-webpack\",\n  \"private\": true,\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"scripts\": {\n    \"build\": \"webpack\"\n  },\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"bs-loader\": \"^1.0.0\",\n    \"reason-react\": \"0.1.3\",\n    \"webpack\": \"^2.2.1\"\n  },\n  \"dependencies\": {\n    \"react\": \"^15.4.2\",\n    \"react-dom\": \"^15.4.2\"\n  }\n}\n\n```\n\n## Using the loader\n\nTo use the loader you must:\n* Register the `.re` and `.ml` extensions with Webpack\n* Configure `.re` and `.ml` to use the loader\n\nAn example config would look like:\n\n```js\n// webpack.config.js\nconst path = require('path')\n\nmodule.exports = {\n  // Entry file can be a Reason or OCaml file\n  entry: './src/entry.re',\n  output: {\n    filename: 'out.js',\n    path: path.resolve(__dirname, 'build')\n  },\n  module: {\n    rules: [\n      // Set up Reason and OCaml files to use the loader\n      { test: /\\.(re|ml)$/, use: 'bs-loader' },\n    ]\n  },\n  resolve: {\n    // Add .re and .ml to the list of extensions webpack recognizes\n    extensions: ['.re', '.ml', '.js']\n  }\n}\n```\n\n## Usage with Jest\n\n`bs-loader` includes a transform for usage with Jest. This lets Jest run\nReason and OCaml files as tests. An example Jest configuration using `bs-loader`:\n\n```\n\"jest\": {\n  \"moduleFileExtensions\": [\n    \"re\",\n    \"js\",\n    \"ml\"\n  ],\n  \"testMatch\": [\n    \"**/src/*_test.re\"\n  ],\n  \"transform\": {\n    \".(re|ml)\": \"bs-loader\"\n  }\n}\n```\n\n## Options\n\nMost of these settings are inferred from your `bsconfig.json`. These are available\nfor manual override, but might go away in the future.\n\n### `module`\n\nTo tell Webpack to load a module type that isn't JS (for example, `amd` or `goog`)\ngive the loader a `module` option. For example, to use AMD modules produced by Bucklescript,\nuse the config\n\n```js\n{ test: /\\.(re|ml)$/, use: 'bs-loader?module=amd' }\n```\n\n### `inSource`\n\nTo use bs-loader with [bsb's in-souce builds](https://bucklescript.github.io/bucklescript/Manual.html#_in_source_build_support_since_1_9_0),\nadd the `inSource` option to your loader config:\n\n```js\n{\n  test: /\\.(re|ml)$/,\n  use: {\n    loader: 'bs-loader',\n    options: {\n      module: 'es6',\n      inSource: true\n    }\n  }\n}\n```\n\n### `cwd`\n\nThis option specifies what directory to run `bsb` from. For example, to\nrun `bsb` from the same directory as your webpack config, use:\n\n```js\n{\n  test: /\\.(re|ml)$/,\n  use: {\n    loader: 'bs-loader',\n    options: {\n     cwd: __dirname\n    }\n  }\n}\n```\n\n### `showWarnings`\n\nControls whether `bsb` compile warnings are shown. Defaults to `true`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrdelaney%2Fbs-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frrdelaney%2Fbs-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrdelaney%2Fbs-loader/lists"}