Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 29 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
</a>
</div>

[![npm][npm]][npm-url]
[![node][node]][node-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![discussion][discussion]][discussion-url]
[![size][size]][size-url]
[![npm](https://img.shields.io/npm/v/coffee-loader.svg)](https://npmjs.com/package/coffee-loader)
[![node](https://img.shields.io/node/v/coffee-loader.svg)](https://nodejs.org)
[![tests](https://github.com/webpack/coffee-loader/workflows/coffee-loader/badge.svg)](https://github.com/webpack/coffee-loader/actions)
[![coverage](https://codecov.io/gh/webpack/coffee-loader/branch/main/graph/badge.svg)](https://codecov.io/gh/webpack/coffee-loader)
[![discussion](https://img.shields.io/github/discussions/webpack/webpack)](https://github.com/webpack/webpack/discussions)
[![size](https://packagephobia.now.sh/badge?p=coffee-loader)](https://packagephobia.now.sh/result?p=coffee-loader)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a plugin for a new site to avoid such changes, we have a lot of such things and I don't want to change it in every repo, also it is the valid syntax

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, are the other changes fine? (Mostly the addition of displayName?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to say it is a normal practice using the such syntax, I don't want to migration of lot of docs to this, let's use markdown plugin(s) to resolve such things and avoid changing multiple readme


# coffee-loader

Expand All @@ -20,27 +20,21 @@ Compile [CoffeeScript](https://coffeescript.org/) to JavaScript.

To begin, you'll need to install `coffeescript` and `coffee-loader`:

```console
```console displayName="npm"
npm install --save-dev coffeescript coffee-loader
```

or

```console
```bash displayName="yarn"
yarn add -D coffeescript coffee-loader
```

or

```console
```bash displayName="pnpm"
pnpm add -D coffeescript coffee-loader
```

Then add the loader to your `webpack.config.js`. For example:

**file.coffee**

```coffee
```coffee displayName="file.coffee"
# Assignment:
number = 42
opposite = true
Expand Down Expand Up @@ -71,9 +65,7 @@ alert "I knew it!" if elvis?
cubes = (math.cube num for num in list)
```

**webpack.config.js**

```js
```js displayName="webpack.config.js"
module.exports = {
module: {
rules: [
Expand All @@ -92,28 +84,20 @@ Alternative usage:
import coffee from "coffee-loader!./file.coffee";
```

Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).
Finally, run `webpack` using the method you normally use (e.g., via CLI or an
npm script).

## Options

Type: `Object`
Default: `{ bare: true }`

You can find all available CoffeeScript options [here](https://coffeescript.org/#nodejs-usage).

For documentation on the `transpile` option, see [this section](https://coffeescript.org/#transpilation).
The `sourceMap` option takes a value from the `compiler.devtool` value by
default.

> [!NOTE]
>
> The `sourceMap` option takes a value from the `compiler.devtool` value by default.
The `filename` option takes a value from webpack loader API, but its value
will be ignored.

> [!NOTE]
>
> The `filename` option takes a value from webpack loader API, but it's value will be ignored.

**webpack.config.js**

```js
```js displayName="webpack.config.js"
module.exports = {
module: {
rules: [
Expand All @@ -136,25 +120,22 @@ module.exports = {

### CoffeeScript and Babel

From CoffeeScript 2 documentation:
CoffeeScript 2 generates JavaScript using the latest, modern syntax. The
runtime or browsers where you want your code to run might not support all of
that syntax. In that case, modern JavaScript needs to be converted into an
older JavaScript that will run in older versions of Node or older browsers;
for example: `{ a } = obj` into `a = obj.a`. This conversion is done using
transpilers like Babel, Bublé or Traceur Compiler.

> [!NOTE]
>
> CoffeeScript 2 generates JavaScript using the latest, modern syntax.
> The runtime or browsers where you want your code to run might not support all of that syntax.
> In that case, modern JavaScript needs to be converted into an older JavaScript that will run in older versions of Node or older browsers; for example: `{ a } = obj` into `a = obj.a`.
> This conversion is done using transpilers like Babel, Bublé or Traceur Compiler.

You'll need to install `@babel/core` and `@babel/preset-env` and then create a configuration file:
You'll need to install `@babel/core` and `@babel/preset-env` and then create a
configuration file:

```console
npm install --save-dev @babel/core @babel/preset-env
echo '{ "presets": ["@babel/env"] }' > .babelrc
```

**webpack.config.js**

```js
```js displayName="webpack.config.js"
module.exports = {
module: {
rules: [
Expand All @@ -174,11 +155,9 @@ module.exports = {

### Literate CoffeeScript

To use Literate CoffeeScript you should setup:
To use Literate CoffeeScript you should set up:

**webpack.config.js**

```js
```js displayName="webpack.config.js"
module.exports = {
module: {
rules: [
Expand All @@ -193,26 +172,3 @@ module.exports = {
},
};
```

## Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

[CONTRIBUTING](https://github.com/webpack/coffee-loader?tab=contributing-ov-file#contributing)

## License

[MIT](./LICENSE)

[npm]: https://img.shields.io/npm/v/coffee-loader.svg
[npm-url]: https://npmjs.com/package/coffee-loader
[node]: https://img.shields.io/node/v/coffee-loader.svg
[node-url]: https://nodejs.org
[tests]: https://github.com/webpack/coffee-loader/workflows/coffee-loader/badge.svg
[tests-url]: https://github.com/webpack/coffee-loader/actions
[cover]: https://codecov.io/gh/webpack/coffee-loader/branch/main/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack/coffee-loader
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
[discussion-url]: https://github.com/webpack/webpack/discussions
[size]: https://packagephobia.now.sh/badge?p=coffee-loader
[size-url]: https://packagephobia.now.sh/result?p=coffee-loader
Loading