@modular-css/svelte

23.0.6 • Public • Published

@modular-css/svelte NPM Version NPM License NPM Downloads

Gitter

Svelte preprocessor support for modular-css. Process inline <style>s or <link> references inside your Svelte components using the full power of modular-css while also providing compile-time optimizations for smaller bundles and even faster runtime performance!

Example

Turns this

<div class="{css.main}">
    <h1 class="{css.title}">Title</h1>
</div>

<style>
    .main {
        ...
    }
    
    .title {
        ...
    }
</style>

into what is effectively this

<div class="abc123_main">
    <h1 class="abc123_title">Title</h1>
</div>

while allowing you to use all of the usual modular-css goodies.

Alternatively you can use <link href="./file.css" /> tags to reference CSS external to the component.

Install

> npm i @modular-css/svelte -D

Usage

svelte.preprocess()

const filename = "./Component.html";

const { processor, preprocess } = require("@modular-css/svelte")({
    // Processor options
});

const processed = await svelte.preprocess(
    fs.readFileSync(filename, "utf8"),
    Object.assign({}, preprocess, { filename })
);

const result = await processor.output();

fs.writeFileSync("./dist/bundle.css", result.css);

@modular-css/rollup

API

const rollup = require("rollup").rollup;

const { preprocess, processor } = require("@modular-css/svelte")({
    // Processor options
});

const bundle = await rollup({
    input   : "./Component.html",
    
    plugins : [
        require("rollup-plugin-svelte")({
            preprocess,
        }),

        require("@modular-css/rollup")({
            processor,

            common : "common.css",
        }),
    ]
});

// bundle.write will also write out the CSS to the path specified in the `css` arg
bundle.write({
    format : "es",
    file   : "./dist/bundle.js"
});

rollup.config.js

const { preprocess, processor } = require("@modular-css/svelte")({
    // Processor options
});

module.exports = {
    input   : "./Component.html",
    
    output  : {
        format : "es",
        file   : "./dist/bundle.js"
    },

    plugins : [
        require("rollup-plugin-svelte")({
            preprocess,
        }),
        
        require("@modular-css/rollup")({
            processor,

            common : "common.css",
        }),
    ]
};

Options

strict

If true whenever a missing replacement is found like {css.doesnotexist} an error will be throw aborting the file processing. Defaults to false.

clean

If true will re-process any previously handled files (and remove any files that dependended on them). Might be useful, but currently also dangerous (see #522). Defaults to false.

Shared Options

All options are passed to the underlying Processor instance, see Options.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
29.0.49latest
27.0.21next

Version History

VersionDownloads (Last 7 Days)Published
29.0.49
29.0.30
29.0.20
29.0.11
29.0.01
28.2.23
28.2.11
28.2.00
28.1.31
28.1.20
28.1.00
28.0.01
27.2.01
27.1.00
27.0.31
27.0.21
27.0.11
27.0.01
26.0.00
25.8.21
25.8.01
25.7.01
25.6.00
25.5.01
25.4.11
25.4.00
25.3.11
25.3.00
25.2.01
25.1.00
25.0.01
24.2.27
24.2.10
24.2.01
24.1.01
24.0.11
24.0.00
23.0.60
23.0.50
23.0.40
23.0.21
23.0.01
22.1.41
22.1.21
22.1.01
22.0.11
22.0.00
21.2.11
21.2.01
21.1.11
21.0.01
20.0.00
19.1.00
19.0.00
18.0.01
17.1.20
17.1.11
17.1.01
17.0.00
16.2.01
16.1.00
16.0.00

Package Sidebar

Install

npm i @modular-css/svelte@23.0.6

Homepage

m-css.com

Version

23.0.6

License

MIT

Unpacked Size

27.5 kB

Total Files

5

Last publish

Collaborators

  • tivac