material-web
material-web copied to clipboard
Quick Start is missing a few steps
Description
As someone who is relatively brand-new to this, I'm trying to follow the quick start guide at https://github.com/material-components/material-web/blob/main/docs/quick-start.md
As instructed, I've installed it by running npm install @material/web
, then I've created index.js
. Then I add the provided HTML to a file.
That's the end of the "Usage" section, which would imply that's all one needs to do in order to use this. However, when I open the resulting HTML file Firefox tells me Uncaught TypeError: The specifier “@material/web/button/filled-button.js” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.
There is a subsequent section on "Building", which appears to be relevant. It says to install rollup @rollup/plugin-node-resolve
and then run npx rollup -p @rollup/plugin-node-resolve index.js -o bundle.js
.
I do get visible output if I change the sample HTML file from index.js
to bundle.js
.
Issues
There are two issues I find:
- The "Usage" section ends just before the interesting bit. How do I actually use it in practice?
- The file should be called
bundle.js
but the "Usage" section calls itindex.js
Browser/OS Environment
Browser: Firefox OS: Windows 11
I understand your complain is about the doc not being detailed enough, v1.0
shipped recently and the doc is still in progress.
Meanwhile here's a little tuto:
You will need to resolve node module paths because your browser can't understand them, a server may be used.
- Create a
package.json
(you can usenpm init
) - Install the bare minimum:
npm i -D @material/web @web/dev-server
- Create a file at
src/test.js
import '@material/web/button/text-button.js';
- Create an
index.html
file at the root
<!doctype html>
<html>
<head></head>
<body>
<md-text-button>Hello World</md-text-button>
<script type="module" src="./src/test.js"></script>
</body>
</html>
- Run the server:
npx wds --node-resolve --open --watch
and follow the url
When you are done developing you can also use @web/dev-server
to build or Rollup or any tool you are used to.
Hope it helps.