UNPKG

2.27 kBMarkdownView Raw
1[![NPM version](https://img.shields.io/npm/v/@minna-ui/preprocess.svg)](https://www.npmjs.com/package/@minna-ui/preprocess)
2[![Licence](https://img.shields.io/npm/l/@minna-ui/preprocess.svg)](https://github.com/WeAreGenki/minna-ui/blob/master/LICENCE)
3
4# `@minna-ui/preprocess`
5
6Collection of Svelte preprocessors for use in [`Minna UI`](https://github.com/WeAreGenki/minna-ui) projects. It consists of a markup preprocessor which strips out excessive whitespace (collapses relevant whitespace down to a single space but leaves appropriate tags alone, e.g. `<pre>`, `<script>`, `<style>`) and a style preprocessor which runs styles through [PostCSS](https://github.com/postcss/postcss).
7
8## Usage
9
10Install:
11
12```sh
13yarn add @minna-ui/preprocess
14```
15
16Next add the preprocessor to your Svelte settings (e.g. in `webpack.config.js` or `rollup.config.js`).
17
18If you want all our preprocessors use the all-in-one preset:
19
20<!-- global svelte -->
21
22```js
23import { preprocess } from '@minna-ui/preprocess';
24
25svelte({
26 preprocess,
27});
28```
29
30Or if you prefer, you can select the preprocessors individually:
31
32<!-- global svelte -->
33
34```js
35import { markup, style } from '@minna-ui/preprocess';
36
37svelte({
38 preprocess: {
39 markup: markup({
40 // only use in production builds for better dev debugging
41 enabled: process.env.NODE_ENV === 'production',
42 }),
43 style: style(),
44 },
45});
46```
47
48### Utils
49
50You can also strip whitespace from any HTML in a string template literal by using the `html` helper:
51
52```js
53import { html } from '@minna-ui/preprocess';
54
55const myMarkup = html`
56 <div>
57 <h1>My Title</h1>
58 </div>
59`;
60
61console.log(myMarkup); // '<div><h1>My Title</h1></div>'
62```
63
64> Tip: If you're using rollup with the setting `treeshake.pureExternalModules = true` ([docs](https://rollupjs.org/guide/en#treeshake)), prepend the call with a pure annotation so the module is tree shaken from the final JS bundle:
65
66<!-- prettier-ignore -->
67```js
68/*#__PURE__*/html`...`; // eslint-disable-line
69```
70
71## Licence
72
73`@minna-ui/preprocess` is part of [`Minna UI`](https://github.com/WeAreGenki/minna-ui), an Apache-2.0 licensed open source project. See [LICENCE](https://github.com/WeAreGenki/minna-ui/blob/master/LICENCE).
74
75---
76
77© 2020 [We Are Genki](https://wearegenki.com)