chayns-toolkit 2.0.0-beta.5 → 2.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +38 -491
- package/babel.js +6 -0
- package/cli.js +1 -1
- package/eslint/index.js +1 -1
- package/lib/cli.js +37 -35
- package/package.json +140 -139
- package/lib/eslint.js +0 -150
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Tobit Software Laboratories AG
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Tobit Software Laboratories AG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
|
|
2
|
+
<a href="https://tobitsoftware.github.io/chayns-toolkit/" target="_blank">
|
|
3
|
+
<h1 align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/TobitSoftware/chayns-toolkit/HEAD/assets/logo.png" width="500px" alt="chayns-toolkit" />
|
|
5
|
+
</h1>
|
|
6
|
+
</a>
|
|
5
7
|
<p align="center">A zero-config toolchain for developing chayns® apps.</p>
|
|
6
8
|
<p align="center">
|
|
7
9
|
<a href="https://github.com/TobitSoftware/chayns-toolkit/blob/master/LICENSE" target="_blank">
|
|
8
|
-
<img src="https://img.shields.io/github/license/TobitSoftware/chayns-toolkit?style=for-the-badge" alt="" />
|
|
10
|
+
<img src="https://img.shields.io/github/license/TobitSoftware/chayns-toolkit?color=%23A855F7&labelColor=%2327272A&style=for-the-badge" alt="" />
|
|
9
11
|
</a>
|
|
10
12
|
<a href="https://www.npmjs.com/package/chayns-toolkit" target="_blank">
|
|
11
|
-
<img src="https://img.shields.io/npm/v/chayns-toolkit?style=for-the-badge" alt="" />
|
|
13
|
+
<img src="https://img.shields.io/npm/v/chayns-toolkit?color=%236366F1&labelColor=%2327272A&style=for-the-badge" alt="" />
|
|
12
14
|
</a>
|
|
13
15
|
<a href="https://github.com/TobitSoftware/chayns-toolkit/branches" target="_blank">
|
|
14
|
-
<img src="https://img.shields.io/github/last-commit/TobitSoftware/chayns-toolkit?style=for-the-badge" alt="" />
|
|
16
|
+
<img src="https://img.shields.io/github/last-commit/TobitSoftware/chayns-toolkit?color=%2310B981&labelColor=%2327272A&style=for-the-badge" alt="" />
|
|
15
17
|
</a>
|
|
16
18
|
</p>
|
|
17
19
|
</div>
|
|
@@ -24,500 +26,45 @@ experience when working with [React](https://reactjs.org).
|
|
|
24
26
|
|
|
25
27
|
> This toolchain is specialized in developing apps and plugins for the
|
|
26
28
|
> [chayns®](https://chayns.org/) platform. If you want to develop a general
|
|
27
|
-
> purpose web app, take a look at [Next.js](https://nextjs.org/)
|
|
28
|
-
> [`create-react-app`](https://create-react-app.dev/).
|
|
29
|
+
> purpose web app, take a look at [Next.js](https://nextjs.org/). <br>
|
|
29
30
|
|
|
30
|
-
>
|
|
31
|
+
<br>
|
|
31
32
|
|
|
32
|
-
##
|
|
33
|
+
## ❯ Getting Started
|
|
33
34
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
- [`chayns-toolkit dev`](#chayns-toolkit-dev)
|
|
37
|
-
- [`chayns-toolkit build`](#chayns-toolkit-build)
|
|
38
|
-
- [`chayns-toolkit lint`](#chayns-toolkit-lint)
|
|
39
|
-
- [`chayns-toolkit test`](#chayns-toolkit-test)
|
|
40
|
-
- [Features](#features)
|
|
41
|
-
- [TypeScript Support](#typescript-support)
|
|
42
|
-
- [(S)CSS Support](#scss-support)
|
|
43
|
-
- [Image Assets](#image-assets)
|
|
44
|
-
- [HMR With `react-refresh` Support](#hmr-with-react-refresh-support)
|
|
45
|
-
- [Using React Devtools](#using-react-devtools)
|
|
46
|
-
- [ESLint Configuration](#eslint-configuration)
|
|
47
|
-
- [Support for custom path aliases](#support-for-custom-path-aliases)
|
|
48
|
-
- [Single-File Builds](#single-file-builds)
|
|
49
|
-
- [Environment Variables](#environment-variables)
|
|
50
|
-
- [Analyzing Your Bundle](#analyzing-your-bundle)
|
|
51
|
-
- [Tree-Shaking `chayns-components`](#tree-shaking-chayns-components)
|
|
52
|
-
- [Adjusting the Webpack Configuration](#adjusting-the-webpack-configuration)
|
|
53
|
-
- [The `toolkit.config.js` Configuration File](#the-toolkitconfigjs-configuration-file)
|
|
54
|
-
- [Notes on Multiple Entrypoints](#notes-on-multiple-entrypoints)
|
|
35
|
+
For the easiest way to start a new chayns® project with chayns-toolkit check out
|
|
36
|
+
[`create-chayns-app`](https://github.com/TobitSoftware/create-chayns-app).
|
|
55
37
|
|
|
56
|
-
|
|
38
|
+
<br>
|
|
57
39
|
|
|
58
|
-
|
|
59
|
-
[`create-chayns-app`](https://github.com/TobitSoftware/create-chayns-app)
|
|
60
|
-
command line tool. It will set up an optimal development environment for you in
|
|
61
|
-
one command.
|
|
40
|
+
## ❯ Documentation
|
|
62
41
|
|
|
63
|
-
|
|
42
|
+
Visit
|
|
43
|
+
[https://tobitsoftware.github.io/chayns-toolkit/](https://tobitsoftware.github.io/chayns-toolkit/)
|
|
44
|
+
to view the full documentation.
|
|
64
45
|
|
|
65
|
-
|
|
46
|
+
<br>
|
|
66
47
|
|
|
67
|
-
|
|
68
|
-
[`http://localhost:1234/`](http://localhost:1234/) or
|
|
69
|
-
[`https://0.0.0.0:1234/`](https://0.0.0.0:1234/) if SSL was configured.
|
|
48
|
+
## ❯ Contributing
|
|
70
49
|
|
|
71
|
-
|
|
72
|
-
[
|
|
73
|
-
file:
|
|
50
|
+
Please see our
|
|
51
|
+
[contributing document](https://tobitsoftware.github.io/chayns-toolkit/docs/contributing).
|
|
74
52
|
|
|
75
|
-
|
|
76
|
-
module.exports = {
|
|
77
|
-
development: {
|
|
78
|
-
host: "123.4.5.6",
|
|
79
|
-
port: 1337,
|
|
80
|
-
cert: "/path/to/cert.crt",
|
|
81
|
-
key: "/path/to/key.key",
|
|
82
|
-
},
|
|
83
|
-
// ...
|
|
84
|
-
}
|
|
85
|
-
```
|
|
53
|
+
<br>
|
|
86
54
|
|
|
87
|
-
|
|
88
|
-
| ------------------ | --------------------------------------------------------------------------------------------- |
|
|
89
|
-
| `-d`, `--devtools` | Debug your application with the standalone React Devtools. [Read more](#using-react-devtools) |
|
|
90
|
-
|
|
91
|
-
> To achieve faster (re-)build times during development this command only
|
|
92
|
-
> transpiles your code to work with the latest versions of Chrome, Safari and
|
|
93
|
-
> Firefox.
|
|
94
|
-
|
|
95
|
-
### `chayns-toolkit build`
|
|
96
|
-
|
|
97
|
-
Compiles your source code for production. The output is emitted into a `build/`
|
|
98
|
-
folder in your project directory.
|
|
99
|
-
|
|
100
|
-
Your code is transpiled to work with browsers matching the following
|
|
101
|
-
[browserslist](https://github.com/browserslist/browserslist) query:
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
>0.5%
|
|
105
|
-
not dead
|
|
106
|
-
not op_mini all
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
You can check the exact browsers and versions this matches at any time by
|
|
110
|
-
running
|
|
111
|
-
|
|
112
|
-
```bash
|
|
113
|
-
npx browserslist ">0.5%, not dead, not op_mini all"
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
| Parameters | Function |
|
|
117
|
-
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
118
|
-
| `-a`, `--analyze` | Analyze your bundle with [`webpack-bundle-analyzer`](https://github.com/webpack-contrib/webpack-bundle-analyzer) after compilation. [Read more](#analyzing-your-bundle) |
|
|
119
|
-
|
|
120
|
-
### `chayns-toolkit lint`
|
|
121
|
-
|
|
122
|
-
Lints your JavaScript and TypeScript source code with
|
|
123
|
-
[ESLint](https://eslint.org/) to report any warnings or errors and automatically
|
|
124
|
-
fix them if possible.
|
|
125
|
-
|
|
126
|
-
We recommend to use our included [ESLint configuration](#eslint-configuration).
|
|
127
|
-
|
|
128
|
-
### `chayns-toolkit test`
|
|
129
|
-
|
|
130
|
-
> This command is currently experimental, meaning that it is not semantically
|
|
131
|
-
> versioned. The API may change at any release.
|
|
132
|
-
|
|
133
|
-
Uses [Jest](https://jestjs.io/) to run all your test suites. By default it will
|
|
134
|
-
run all files matching the default Jest Glob:
|
|
135
|
-
|
|
136
|
-
- Any file ending with `.spec.@(js|jsx|ts|tsx)` or `.test.@(js|jsx|ts|tsx)`
|
|
137
|
-
- Any JavaScript or TypeScript file in a folder named `__tests__`
|
|
138
|
-
|
|
139
|
-
The matchers from
|
|
140
|
-
[`@testing-library/jest-dom`](https://testing-library.com/docs/dom-testing-library/intro/)
|
|
141
|
-
will automatically be injected into the Jest environment, so you can write
|
|
142
|
-
assertions on the DOM like this:
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
import { render } from "@testing-library/react"
|
|
146
|
-
import { MyComponent } from "./MyComponent"
|
|
147
|
-
|
|
148
|
-
test('should have "Click Me!" as its text', () => {
|
|
149
|
-
const { getByRole } = render(<MyComponent />)
|
|
150
|
-
|
|
151
|
-
expect(getByRole("button")).toHaveTextContent("Click Me!")
|
|
152
|
-
})
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
| Parameters | Function |
|
|
156
|
-
| -------------------- | -------------------------------------------------------------- |
|
|
157
|
-
| `-w`, `--watch` | Runs Jest in [watch mode](https://jestjs.io/docs/cli#--watch) |
|
|
158
|
-
| `--setupFile <path>` | Executes the setup file specified by `<path>` before any tests |
|
|
159
|
-
|
|
160
|
-
## Features
|
|
161
|
-
|
|
162
|
-
- [TypeScript Support](#typescript-support)
|
|
163
|
-
- [(S)CSS Support](#scss-support)
|
|
164
|
-
- [Image Assets](#image-assets)
|
|
165
|
-
- [HMR With `react-refresh` Support](#hmr-with-react-refresh-support)
|
|
166
|
-
- [Using React Devtools](#using-react-devtools)
|
|
167
|
-
- [ESLint Configuration](#eslint-configuration)
|
|
168
|
-
- [Support for custom path aliases](#support-for-custom-path-aliases)
|
|
169
|
-
- [Single-File Builds](#single-file-builds)
|
|
170
|
-
- [Environment Variables](#environment-variables)
|
|
171
|
-
- [Analyzing Your Bundle](#analyzing-your-bundle)
|
|
172
|
-
- [Tree-Shaking `chayns-components`](#tree-shaking-chayns-components)
|
|
173
|
-
- [Adjusting the Webpack Configuration](#adjusting-the-webpack-configuration)
|
|
174
|
-
|
|
175
|
-
### TypeScript Support
|
|
176
|
-
|
|
177
|
-
TypeScript is fully supported.
|
|
178
|
-
|
|
179
|
-
#### Getting Started
|
|
180
|
-
|
|
181
|
-
To start using TypeScript in your project, create a `tsconfig.json` file in the
|
|
182
|
-
root of your project or create a `.ts` or `.tsx` file in your `src/` directory.
|
|
183
|
-
The next time you start the `chayns-toolkit dev` command, we will automatically
|
|
184
|
-
populate/create the `tsconfig.json`-file with our recommended configuration.
|
|
185
|
-
|
|
186
|
-
> If you do not have a `tsconfig.json` file and use `.ts` or `.tsx` files,
|
|
187
|
-
> ESLint will not be able to check these for errors.
|
|
188
|
-
|
|
189
|
-
You are now ready to use TypeScript in your `.ts` and `.tsx` files!
|
|
190
|
-
|
|
191
|
-
#### Caveats
|
|
192
|
-
|
|
193
|
-
The TypeScript compilation is done by
|
|
194
|
-
[`@babel/preset-typescript`](https://babeljs.io/docs/en/babel-preset-typescript).
|
|
195
|
-
This has some caveats, mainly not being able to use `const enum` and `export =`
|
|
196
|
-
or `import =`.
|
|
197
|
-
|
|
198
|
-
The automatically generated `tsconfig.json` includes `"isolatedModules": true`
|
|
199
|
-
in the TypeScript compiler options, which will make the TypeScript compiler warn
|
|
200
|
-
you about using unsupported features.
|
|
201
|
-
|
|
202
|
-
Refer to the
|
|
203
|
-
[Babel documentation](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats)
|
|
204
|
-
for more information.
|
|
205
|
-
|
|
206
|
-
### (S)CSS Support
|
|
207
|
-
|
|
208
|
-
You can import `.css` and `.scss` files into your JavaScript/TypeScript files to
|
|
209
|
-
include them in the bundling process:
|
|
210
|
-
|
|
211
|
-
```js
|
|
212
|
-
import "./my-styles.scss"
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
#### CSS Modules
|
|
216
|
-
|
|
217
|
-
CSS modules are also supported. Every file ending with `.module.css` or
|
|
218
|
-
`.module.scss` will be treated as a module. Use it like this:
|
|
219
|
-
|
|
220
|
-
```jsx
|
|
221
|
-
import styles from "styles.css"
|
|
222
|
-
|
|
223
|
-
export function MyComponent() {
|
|
224
|
-
return <div className={styles.box}>I am styled with CSS modules!</div>
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
> For more information on CSS Modules check out
|
|
229
|
-
> [this article](https://css-tricks.com/css-modules-part-1-need/).
|
|
230
|
-
|
|
231
|
-
### Image Assets
|
|
232
|
-
|
|
233
|
-
Images with `.png`, `.jpg`, `.jpeg`, `.gif` or `.webp` extensions can be
|
|
234
|
-
imported into your components and will be included in the bundle. The default
|
|
235
|
-
export of an image module is its resulting URL:
|
|
236
|
-
|
|
237
|
-
```jsx
|
|
238
|
-
import imgSrc from "./my-image.png"
|
|
239
|
-
|
|
240
|
-
export function MyImage() {
|
|
241
|
-
return <img src={imgSrc} alt="" />
|
|
242
|
-
}
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
> Small images (< 10 KB) will be inlined into the JavaScript code with data-urls
|
|
246
|
-
> and therefore won't appear as files in your output. This improves loading
|
|
247
|
-
> times. When single-file mode is activated, all images will be inlined.
|
|
248
|
-
|
|
249
|
-
#### SVG Support
|
|
250
|
-
|
|
251
|
-
Importing `.svg` files automatically converts them to React components. They
|
|
252
|
-
take any of the props a regular `<svg>`-element would take:
|
|
253
|
-
|
|
254
|
-
```jsx
|
|
255
|
-
import Icon from "./my-icon.svg"
|
|
256
|
-
|
|
257
|
-
export function MyIcon() {
|
|
258
|
-
return <Icon className="icon" />
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### HMR With `react-refresh` Support
|
|
263
|
-
|
|
264
|
-
The development server supports hot module reloading with
|
|
265
|
-
[`react-refresh`](https://github.com/pmmmwh/react-refresh-webpack-plugin),the
|
|
266
|
-
improved alternative to the now deprecated `react-hot-loader`.
|
|
267
|
-
|
|
268
|
-
This allows you to see changes in your React components in real-time after
|
|
269
|
-
saving without losing component state. Some patterns will force a full reload,
|
|
270
|
-
for further information refer to
|
|
271
|
-
[this paragraph](https://github.com/pmmmwh/react-refresh-webpack-plugin#caveats).
|
|
272
|
-
|
|
273
|
-
### Using React Devtools
|
|
274
|
-
|
|
275
|
-
Sometimes you might not be able to use the React Devtools browser extension,
|
|
276
|
-
e.g. when developing inside of an iframe.
|
|
277
|
-
|
|
278
|
-
For this case we support using the standalone React Devtools via the
|
|
279
|
-
[`react-devtools`](https://github.com/facebook/react/tree/master/packages/react-devtools)-package.
|
|
280
|
-
First you have to install it as a development dependency:
|
|
281
|
-
|
|
282
|
-
```bash
|
|
283
|
-
# Yarn
|
|
284
|
-
yarn add react-devtools -D
|
|
285
|
-
|
|
286
|
-
# NPM
|
|
287
|
-
npm install react-devtools -D
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
Now you can pass the `-d` (or `--devtools`) option to `chayns-toolkit dev`. It
|
|
291
|
-
then starts the React Devtools window, which will connect to your application
|
|
292
|
-
once it has loaded in the browser.
|
|
293
|
-
|
|
294
|
-
### ESLint Configuration
|
|
295
|
-
|
|
296
|
-
Our ESLint-config `@chayns-toolkit/eslint-config` is automatically included when
|
|
297
|
-
`chayns-toolkit` is installed.
|
|
298
|
-
|
|
299
|
-
To activate the config add an `eslintConfig` key to your `package.json`:
|
|
300
|
-
|
|
301
|
-
```json
|
|
302
|
-
{
|
|
303
|
-
"...": "",
|
|
304
|
-
"eslintConfig": {
|
|
305
|
-
"extends": "@chayns-toolkit"
|
|
306
|
-
},
|
|
307
|
-
"...": ""
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
or use one of the
|
|
312
|
-
[other options for configuring ESLint](https://eslint.org/docs/user-guide/configuring#using-configuration-files-1).
|
|
313
|
-
|
|
314
|
-
The configuration can also be installed as a standalone package
|
|
315
|
-
(`@chayns-toolkit/eslint-config`).
|
|
316
|
-
|
|
317
|
-
If you think a rule should be enabled, disabled or adjusted, please consider
|
|
318
|
-
[opening an issue](https://github.com/TobitSoftware/chayns-toolkit/issues/new)
|
|
319
|
-
to discuss the suggested change instead of changing your local configuration.
|
|
320
|
-
|
|
321
|
-
### Support for custom path aliases
|
|
322
|
-
|
|
323
|
-
`chayns-toolkit` supports the `paths` and `baseUrl` options from `tsconfig.json`
|
|
324
|
-
or `jsconfig.json` to create more readable paths.
|
|
325
|
-
|
|
326
|
-
You can set the `baseUrl` like so:
|
|
327
|
-
|
|
328
|
-
```json
|
|
329
|
-
// tsconfig.json or jsconfig.json for non-TypeScript projects
|
|
330
|
-
{
|
|
331
|
-
"compilerOptions": {
|
|
332
|
-
"baseUrl": "./src"
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Then you can import files based on your `baseUrl`:
|
|
338
|
-
|
|
339
|
-
```ts
|
|
340
|
-
// Import `MyComponent` from `./src/components/MyComponent`
|
|
341
|
-
import { MyComponent } from "components/MyComponent"
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
If you want to know more about
|
|
345
|
-
[`baseUrl`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#base-url)
|
|
346
|
-
and
|
|
347
|
-
[`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping)
|
|
348
|
-
check the TypeScript docs.
|
|
349
|
-
|
|
350
|
-
### Single-File Builds
|
|
351
|
-
|
|
352
|
-
In single-file build mode, the compiler will inline all assets (CSS, images,
|
|
353
|
-
etc.) together with all JavaScript into a single bundle. This can be useful when
|
|
354
|
-
building smaller fragments of a UI, e.g. some kind of plugin.
|
|
355
|
-
|
|
356
|
-
### Environment Variables
|
|
357
|
-
|
|
358
|
-
All system environment variables as well as any variables specified in a
|
|
359
|
-
`.env.local` file in the root of your project directory will be available to
|
|
360
|
-
your code under `process.env.VAR_NAME`
|
|
361
|
-
|
|
362
|
-
This allows you to specify environment variables in your CI/CD solution and use
|
|
363
|
-
them in your source code.
|
|
364
|
-
|
|
365
|
-
> Please note that this is a string based replacement. Only
|
|
366
|
-
> `process.env.VAR_NAME` will be replaced, but other syntax like
|
|
367
|
-
> `const { GOOGLE_API_KEY } = process.env` might not be detected.
|
|
368
|
-
|
|
369
|
-
### Analyzing Your Bundle
|
|
370
|
-
|
|
371
|
-
By passing the `--analyze` flag to `chayns-toolkit build` you can use
|
|
372
|
-
[`webpack-bundle-analyzer`](https://github.com/webpack-contrib/webpack-bundle-analyzer)
|
|
373
|
-
to investigate your bundle-size. It will automatically open the tree-map of your
|
|
374
|
-
bundled files after compiling. It runs for as long as you keep the terminal
|
|
375
|
-
process alive.
|
|
376
|
-
|
|
377
|
-
### Tree-Shaking `chayns-components`
|
|
378
|
-
|
|
379
|
-
The tree-shaking for
|
|
380
|
-
[`chayns-components`](https://github.com/TobitSoftware/chayns-components) is
|
|
381
|
-
built into the build configuration and configured automatically. For further
|
|
382
|
-
information refer to
|
|
383
|
-
[this document](https://github.com/TobitSoftware/chayns-components/blob/master/tree-shaking.md).
|
|
384
|
-
|
|
385
|
-
If your bundle size is unexpectedly large, please
|
|
386
|
-
[open an issue](https://github.com/TobitSoftware/chayns-toolkit/issues/new).
|
|
387
|
-
|
|
388
|
-
### Adjusting the Webpack Configuration
|
|
389
|
-
|
|
390
|
-
Even though the included webpack configuration will handle most cases, we also
|
|
391
|
-
provide the ability to modify it.
|
|
392
|
-
|
|
393
|
-
> Please note that the webpack configuration does not follow SemVer and it could
|
|
394
|
-
> change during any release, even patch releases.
|
|
395
|
-
|
|
396
|
-
Use the `webpack` property of the configuration object to specify a function
|
|
397
|
-
that receives the default webpack configuration along with some other
|
|
398
|
-
information. This modifier function has to return the modified configuration.
|
|
399
|
-
|
|
400
|
-
The modifier function receives two arguments. First is our default webpack
|
|
401
|
-
configuration, second is an object with additional information and utilities,
|
|
402
|
-
following this interface:
|
|
403
|
-
|
|
404
|
-
```ts
|
|
405
|
-
interface Options {
|
|
406
|
-
/**
|
|
407
|
-
* The webpack module. Do not import webpack on your own if you want to use
|
|
408
|
-
* one of the built-in plugins.
|
|
409
|
-
*/
|
|
410
|
-
webpack: webpack
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* A boolean that specifies wether the configuration is for local
|
|
414
|
-
* development or production.
|
|
415
|
-
*/
|
|
416
|
-
dev: boolean
|
|
417
|
-
}
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
This is an example of editing the webpack configuration by adding
|
|
421
|
-
`@babel/plugin-proposal-pipeline-operator` to `babel-loader`:
|
|
422
|
-
|
|
423
|
-
```js
|
|
424
|
-
module.exports = {
|
|
425
|
-
webpack(config) {
|
|
426
|
-
const babelRule = config.module.rules.find(
|
|
427
|
-
(rule) =>
|
|
428
|
-
rule.use.loader && rule.use.loader.includes("babel-loader")
|
|
429
|
-
)
|
|
430
|
-
|
|
431
|
-
if (!babelRule) return config
|
|
432
|
-
|
|
433
|
-
const babelOptions = babelRule.use.options
|
|
434
|
-
|
|
435
|
-
const pipelinePlugin = [
|
|
436
|
-
"@babel/plugin-proposal-pipeline-operator",
|
|
437
|
-
{ proposal: "smart" },
|
|
438
|
-
]
|
|
439
|
-
|
|
440
|
-
if (Array.isArray(babelOptions.plugins)) {
|
|
441
|
-
babelOptions.plugins.push(pipelinePlugin)
|
|
442
|
-
} else {
|
|
443
|
-
babelOptions.plugins = [pipelinePlugin]
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
return config
|
|
447
|
-
},
|
|
448
|
-
}
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
If you find yourself modifying the webpack configuration often for a feature
|
|
452
|
-
that you think belongs in our default config, please
|
|
453
|
-
[open an issue](https://github.com/TobitSoftware/create-chayns-app/issues) to
|
|
454
|
-
discuss it.
|
|
455
|
-
|
|
456
|
-
## The `toolkit.config.js` Configuration File
|
|
457
|
-
|
|
458
|
-
You can configure certain aspects of the commands with the `toolkit.config.js`
|
|
459
|
-
file in the root of your project directory.
|
|
460
|
-
|
|
461
|
-
This is an example of the `toolkit.config.js`-file with all available options
|
|
462
|
-
specified:
|
|
463
|
-
|
|
464
|
-
```js
|
|
465
|
-
module.exports = {
|
|
466
|
-
development: {
|
|
467
|
-
host: "123.0.0.1",
|
|
468
|
-
port: 1337,
|
|
469
|
-
cert: "//path/to/ssl/cert",
|
|
470
|
-
key: "//path/to/ssl/key",
|
|
471
|
-
},
|
|
472
|
-
output: {
|
|
473
|
-
singleBundle: false,
|
|
474
|
-
filename: "[package].[contenthash].js",
|
|
475
|
-
path: "//my-qa-server/example-project",
|
|
476
|
-
},
|
|
477
|
-
webpack(config, { webpack, dev }) {
|
|
478
|
-
// modify the webpack configuration...
|
|
479
|
-
|
|
480
|
-
return modifiedConfig
|
|
481
|
-
},
|
|
482
|
-
}
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
### `development` Options:
|
|
486
|
-
|
|
487
|
-
These options configure your development server started by the
|
|
488
|
-
`chayns-toolkit dev` command:
|
|
489
|
-
|
|
490
|
-
| Option | Type | Explanation |
|
|
491
|
-
| ---------- | -------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
492
|
-
| **`host`** | `string` | The hostname of your development server. Defaults to `localhost` or `0.0.0.0` if both `cert` and `key` are provided. |
|
|
493
|
-
| **`port`** | `number` | The port of your development server. Defaults to `1234`. |
|
|
494
|
-
| **`cert`** | `string` | The path to a SSL certificate file for your development server. Not specified by default. |
|
|
495
|
-
| **`key`** | `string` | The path to a SSL key file for your development server. Not specified by default. |
|
|
496
|
-
|
|
497
|
-
### `output` Options:
|
|
498
|
-
|
|
499
|
-
These options configure your build output generated by the
|
|
500
|
-
`chayns-toolkit build` command:
|
|
501
|
-
|
|
502
|
-
| Option | Type | Explanation |
|
|
503
|
-
| ------------------ | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
504
|
-
| **`singleBundle`** | `boolean` | Toggles the [single-file build functionality](#single-file-builds). |
|
|
505
|
-
| **`filename`** | `string` | Change the file-name your of primary output bundle. You can use any of the [webpack substitutions](https://webpack.js.org/configuration/output/#template-strings) as well as the `[package]` substitution (will be replaced by the name specified in your `package.json`). Defaults to `[package].[contenthash].js`. |
|
|
506
|
-
| **`path`** | `string` | Set an absolute path where your output will be emitted to (e.g. build directly to a directory that is accessible via HTTPS on a QA server). |
|
|
507
|
-
|
|
508
|
-
### The `webpack` Option:
|
|
509
|
-
|
|
510
|
-
Please refer to the
|
|
511
|
-
["Adjusting the webpack configuration"](#adjusting-the-webpack-configuration)
|
|
512
|
-
section.
|
|
513
|
-
|
|
514
|
-
## Notes on Multiple Entrypoints
|
|
515
|
-
|
|
516
|
-
Some projects use multiple webpack entrypoints for different outputs to reduce
|
|
517
|
-
configuration duplication. Since this package gets rid of your build
|
|
518
|
-
configuration, a project with multiple entrypoints make much sense. Therefore we
|
|
519
|
-
do not currently support multiple entrypoints.
|
|
55
|
+
---
|
|
520
56
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
57
|
+
<p align="center">
|
|
58
|
+
<sub>
|
|
59
|
+
Project created by Leo Driesch at Tobit.Software.
|
|
60
|
+
</sub>
|
|
61
|
+
</p>
|
|
62
|
+
<p align="center">
|
|
63
|
+
<a href="https://labs.tobit.com/">
|
|
64
|
+
<img alt="Tobit.Software homepage" src="./assets/icons/globe.svg">
|
|
65
|
+
</a>
|
|
66
|
+
|
|
67
|
+
<a href="https://github.com/TobitSoftware">
|
|
68
|
+
<img alt="Tobit.Software on GitHub" src="./assets/icons/github.svg">
|
|
69
|
+
</a>
|
|
70
|
+
</p>
|
package/babel.js
CHANGED
package/cli.js
CHANGED
package/eslint/index.js
CHANGED
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
extends: ["airbnb", "airbnb/hooks", "prettier"],
|
|
20
20
|
globals: { chayns: true },
|
|
21
21
|
rules: { ...sharedRules, ...javascriptRules },
|
|
22
|
-
parser: "babel-
|
|
22
|
+
parser: "@babel/eslint-parser",
|
|
23
23
|
settings: {
|
|
24
24
|
"import/resolver": {
|
|
25
25
|
typescript: { project: "@(jsconfig|tsconfig).json" },
|