├── .editorconfig
├── .gitattributes
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── index.js
├── package-lock.json
├── package.json
└── test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | indent_style = tab
7 | tab_width = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.{md,yml}]
12 | indent_style = space
13 |
14 | [*.md]
15 | trim_trailing_whitespace = false
16 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | coverage
2 | node_modules
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | if: branch !~ ^v\d
2 | dist: xenial
3 | language: node_js
4 | node_js: node
5 | cache: npm
6 | after_success: node_modules/.bin/nyc report | npx coveralls
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | ISC License (ISC)
2 | Copyright 2017 - 2018 Shinnosuke Watanabe
3 |
4 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
5 |
6 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gulp-svelte
2 |
3 | [](https://www.npmjs.com/package/gulp-svelte)
4 | [](https://travis-ci.com/shinnn/gulp-svelte)
5 | [](https://coveralls.io/github/shinnn/gulp-svelte?branch=master)
6 |
7 | A [gulp](https://github.com/gulpjs/gulp) plugin to compile [Svelte](https://svelte.technology/) templates to JavaScript
8 |
9 | ## Installation
10 |
11 | [Use](https://docs.npmjs.com/cli/install/) [npm](https://docs.npmjs.com/about-npm/).
12 |
13 | ```
14 | npm install --save-dev gulp-svelte
15 | ```
16 |
17 | ## API
18 |
19 | ```javascript
20 | const gulpSvelte = require('gulp-svelte');
21 | ```
22 |
23 | ### gulpSvelte([*options*])
24 |
25 | *options*: `Object` ([options for Svelte compiler API](https://github.com/sveltejs/svelte#compiler-options) and [`preprocess` option](#optionspreprocess))
26 | Return: [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform)
27 |
28 | ```javascript
29 | const {dest, src, task} = require('gulp');
30 | const gulpSvelte = require('gulp-svelte');
31 |
32 | task('default', () => {
33 | return src('index.html') // index.html: '
Hi {{author}}.
'
34 | .pipe(gulpSvelte())
35 | .pipe(dest('dest')); // dest/index.js: 'function create_main_fragment ( state, component ) { ...'
36 | });
37 | ```
38 |
39 | Note:
40 |
41 | * `format` option doesn't support legacy JavaScript formats `amd`, `iife` and `umd`.
42 | * `onerror` option is not supported.
43 | * If `css` option receives `false`, it also emits an extracted CSS as a separate [`Vinyl`](https://github.com/gulpjs/vinyl) object with a `.css` file extension.
44 |
45 | ```javascript
46 | const {dest, src, task} = require('gulp');
47 | const gulpSvelte = require('gulp-svelte');
48 |
49 | task('default', () => {
50 | return src('source.html') // source.html: 'Hello
'
51 | .pipe(gulpSvelte({css: false}))
52 | .pipe(dest('dest'));
53 | // dest/source.js: '... p = createElement("p"); p.className = "svelte-16e8uch"; ...'
54 | // dest/source.css: 'p.svelte-16e8uch{color:red}'
55 | });
56 | ```
57 |
58 | #### options.preprocess
59 |
60 | Type: `Object`
61 |
62 | Modify contents with [`svelte.preprocess()`](https://github.com/sveltejs/svelte#preprocessor-options) passing this option to it before compiling the template.
63 |
64 | ```javascript
65 | const {dest, src, task} = require('gulp');
66 | const gulpSvelte = require('gulp-svelte');
67 |
68 | task('default', () => {
69 | return src('index.html') // index.html: 'original'
70 | .pipe(gulpSvelte({
71 | preprocess: {
72 | markup({content}) {
73 | return {code: content.replace('original', 'modified')}
74 | }
75 | }
76 | }))
77 | .pipe(dest('dest')); // dest/index.js: '... b = createElement("b");\n\t\t\tb.textContent = "modified"; ...'
78 | });
79 | ```
80 |
81 | ## License
82 |
83 | [ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe
84 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const {inspect} = require('util');
4 | const {Transform} = require('stream');
5 |
6 | const {compile, preprocess} = require('svelte');
7 | const inspectWithKind = require('inspect-with-kind');
8 | const isPlainObject = require('is-plain-object');
9 | const {isVinyl} = require('vinyl');
10 | const PluginError = require('plugin-error');
11 | const vinylSourcemapsApply = require('vinyl-sourcemaps-apply');
12 |
13 | const preprocessors = new Set(['markup', 'script', 'style']);
14 |
15 | module.exports = function gulpSvelte(...args) {
16 | const argLen = args.length;
17 |
18 | if (argLen > 1) {
19 | throw new PluginError('gulp-svelte', new RangeError(`Expected 0 or 1 argument (