Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

javascript - Precompile Material Design For Web

I am going to be using Material Design For Web in a PHP application with a custom theme. I am looking for instructions on how to precompile the JS and CSS with my custom theme variables so that I can just pull in the js and css like you would if using the CDN. It appears the CDN does offer some custom themed color options, but none look like what I am looking for which is why I am looking to create my own precompiled css and js files

What are the steps to precompile with the custom theme variables so that I can just have a dist css and js file?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Although this question is kind of too generic, I do understand why it appeared. is not very easy to start with. Docs and examples are scarce and sometimes it is hard to understand how to do even basic things.

To be able to compile it with your own custom theme variables you need:

  1. Setup SASS compilation in your project if you don't have it yet.
  2. Add npm package "material-components-web" as a dependency.
  3. In your root SCSS-file configure MDC theme with your colors like this:
@use '@material/theme' with (
  $primary: #212121,
  $on-primary: #ffffff,
  $secondary: #ffc629,
  $background: #33333D,
  $surface: #ffffff,
  $on-surface: #000000
);
  1. After that you can include rest of the MDC's SCSS like this:
@use 'material-components-web/material-components-web'
  1. Since you need to customize only CSS, I suggest you reference existing precompiled JS. Otherwise you'll need to configure babel compilation as well.

You can use basic-material-starter-kit as an example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...