Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/readme update #85

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ stylesheets: {
If you use something other than [Brunch](https://brunch.io) to manage your assets,
you need to add the files to the assets manager of choice.


## Javascript

If you wish to use the accompanying [cell-js](https://github.com/DefactoSoftware/cell-js)
Expand Down Expand Up @@ -239,3 +240,66 @@ Builder.register(AvatarCell, "User-AvatarCell");
```

When in doubt, the cell name corresponds to the `data-cell` attribute on the DOM element.


## Webpack configuration

If you use webpack, you can easily configure it.

#### 1. Import the context of the folder in which you have cells. Next import the library into app.js, which is a webpack input file:

```js
// assets/src/js/app.js

...
const importAll = function(r) {
r.keys().forEach(r)
}

importAll(require.context("../../../lib/YOUR_DIRECTORY/cells", true, /\.js$/))

import Builder from "@vendor/cell/builder" // <-- @vendor is an alias from webpack.config.js, take a look below.
...
```

#### 2. Create aliases in the webpack configuration file:

```js
// assets/webpack.config.js

...
resolve: {
symlinks: false,
modules: ["node_modules"],
alias: {
"@": path.resolve(__dirname, "./src/js"),
"@cells": path.resolve(__dirname, "../lib/YOUR_DIRECTORY/cells"),
"@vendor": path.resolve(__dirname, "./vendor"),
"@libs": path.resolve(__dirname, "./node_modules")
}
},
...
```

#### 3. Also works fine with [cell-js](https://github.com/DefactoSoftware/cell-js) plugin. Just create the index.js file in the target cell and use the aliases to import the library.

#### E.g. calendar:

```js
// cells/calendar/index.js

...
import Cell from "@vendor/cell/cell"
import Builder from "@vendor/cell/builder"
Copy link
Collaborator

Choose a reason for hiding this comment

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

How did you install cell-js? I would expect this:

import { Cell, Builder } from "@defacto/cell-js";

Would you mind sharing your webpack entry config?

Choose a reason for hiding this comment

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

Thanks, I'll respond for couple hours :)

Choose a reason for hiding this comment

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

In assets i have src folder and app.js file which is the entry point of my webpack.config.js

  entry: {
    "./js/app.js": "./src/js/app.js"
  },

But now i see that i have a copy of builder.js and cell.js lib in vendor folder. I'll try import it from node modules.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But now i see that i have a copy of builder.js and cell.js lib in vendor folder. I'll try import it from node modules.

That explains 😄
Let me know if importing the package works fo you. If so I'd say we use this in the examples so we can get this merged 🚀

import moment from "@libs/moment" // <-- JS library

class CalendarCell extends Cell {
initialize() {}
}

Builder.register(CalendarCell, "CalendarCell")

export default CalendarCell

...
```