最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How could I integrate Materialize CSS and JavaScript components into Svelte - Stack Overflow

programmeradmin3浏览0评论

I'm new to Svelte, and I want to build my next project with it.

I want to use Materialize for CSS and JavaScript ponents, but I couldn't find a way to set it up and integrate with Svelte.

How could I do that?

I'm new to Svelte, and I want to build my next project with it.

I want to use Materialize for CSS and JavaScript ponents, but I couldn't find a way to set it up and integrate with Svelte.

How could I do that?

Share Improve this question asked Dec 12, 2019 at 22:06 The Cubear GuyThe Cubear Guy 3815 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Install the materialize-css package with yarn add -D materialize-css.

The stock Svelte template (https://github./sveltejs/template) has 2 CSS imports in public/index.html

<!-- base styles -->
<link rel='stylesheet' href='/global.css'>

<!-- styles that were defined in the ponents -->
<link rel='stylesheet' href='/build/bundle.css'>

Let's adjust how the CSS is built. Instead of global.css, we'll merge global.css and materialize/dist/materialize.css into one file.

There is a rollup plugin called rollup-plugin-css-only that can do this.

yarn add -D rollup-plugin-css-only

In rollup.config.js, configure the plugin by importing it import css from 'rollup-plugin-css-only' and add the css({output: "public/build/base.css"}) to the list of plugins.

Now we can import .css files in src/main.js:

import '../node_modules/materialize-css/dist/css/materialize.css'
import '../public/global.css'

// import js stuff too
import '../node_modules/materialize-css/dist/js/materialize'

....

// init material plugins
M.AutoInit()

Don't forget to update public/index.html to include the generated base.css instead of global.css:

- <link rel='stylesheet' href='/global.css'>
+ <link rel='stylesheet' href='/build/base.css'>

Demo

I have developed this template with Svelte + MaterializeCSS and SMUI (Svelte Material UI) >> Svelte + MaterializeCSS + SMUI

发布评论

评论列表(0)

  1. 暂无评论