Skip to content

Commit

Permalink
Merge branch 'master' of github.com:seek-oss/sku into remove-dev-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Oct 10, 2024
2 parents afed64c + a7565d6 commit 6d34b19
Show file tree
Hide file tree
Showing 5 changed files with 4,708 additions and 4,661 deletions.
54 changes: 54 additions & 0 deletions docs/docs/extra-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,60 @@ Any combination of function name and library name is supported.
[Node.js built-in]: https://nodejs.org/api/assert.html
[browser port]: https://www.npmjs.com/package/assert

## Environment-specific code

`sku` [configures][nodeEnv optimization] webpack to replace all instances of `process.env.NODE_ENV` with its actual value.
During the `start` and `start-ssr` commands, `process.env.NODE_ENV` is replaced with `'development'`.
During the `build` and `build-ssr` commands, `process.env.NODE_ENV` is replaced with `'production'`.

Combined with dead code elimination during minification, this allows you to write environment-specific code that is removed in production.

For example, consider the following code:

```js
import someDevOnlyFunction from './some-dev-only-function';
import someProdOnlyFunction from './some-prod-only-function';
if (process.env.NODE_ENV === 'development') {
someDevOnlyFunction();
}
if (process.env.NODE_ENV === 'production') {
someProdOnlyFunction();
}
```

In development this code would be transformed into:

```js
import someDevOnlyFunction from './some-dev-only-function';
import someProdOnlyFunction from './some-prod-only-function';
if ('development' === 'development') {
someDevOnlyFunction();
}
if ('development' === 'production') {
someProdOnlyFunction();
}
```

Note that both `if` statements are still present in the code, but clearly only `someDevOnlyFunction` will be called.

However, in production, the code would be transformed into:

```js
import someProdOnlyFunction from './some-prod-only-function';
someProdOnlyFunction();
```

The first `if` block is removed entirely as its condition is always `false`.
This allows the `someDevOnlyFunction` import to be removed as well.
The second `if` block is removed, however the contents of the block are kept as its condition is always `true`.

[nodeEnv optimization]: https://webpack.js.org/configuration/optimization/#optimizationnodeenv

## DevServer Middleware

Supply a `devServerMiddleware` path in your sku config to access the internal dev [Express] server.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/storybook.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
...config,
include: [
'**/*', // Implicit default value if `include` is not set and `files` is not set
'.storybook/*', // 👈 Add this line
'.storybook/**/*', // 👈 Add this line
],
}),
} satisfies SkuConfig;
Expand Down
Loading

0 comments on commit 6d34b19

Please sign in to comment.