2 Star 0 Fork 0

mirrors_Rich-Harris / svelte-preprocessor-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

svelte preprocessor demo

You can use HTML, CSS and JS preprocessors with Svelte via svelte.preprocess — docs on the README.

If you're using rollup-plugin-svelte, you can add a preprocess: {...} option to your config, and it'll take care of it for you.

Take a look at App.html...

<h1>Hello {{name}}!</h1>

<style type='text/scss'>
  @import 'variables';

  h1 {
    color: $brand;
  }
</style>

...variables.scss...

$brand: rgb(170,30,30);

...and rollup.config.js:

plugins: [
  svelte({
    // ...
    preprocess: {
      style: ({ content, attributes }) => {
        if (attributes.type !== 'text/scss') return;

        return new Promise((fulfil, reject) => {
          sass.render({
            data: content,
            includePaths: ['src'],
            sourceMap: true,
            outFile: 'x' // this is necessary, but is ignored
          }, (err, result) => {
            if (err) return reject(err);

            fulfil({
              code: result.css.toString(),
              map: result.map.toString()
            });
          });
        });
      }
    }
  }),
  // ...
]

Future work

This is a good start, but we also need the following:

  • Svelte should compose sourcemaps from preprocessors, so that your devtools point all the way back to the code that you authored, not the output of svelte.preprocess
  • Rather than manually building the preprocessor, as above, it would be better to have a svelte-preprocess-scss package that hid all the boilerplate
  • Support in loaders besides rollup-plugin-svelte

As a stretch goal, it would nice if our bundler could know about the dependency on variables.scss.

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_Rich-Harris/svelte-preprocessor-demo.git
git@gitee.com:mirrors_Rich-Harris/svelte-preprocessor-demo.git
mirrors_Rich-Harris
svelte-preprocessor-demo
svelte-preprocessor-demo
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891