rollup-plugin-sass-bundle 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/index.js +120 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Traykovski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} SassPluginOptions
|
|
6
|
+
* @property {Parameters<CreateFilter>[1]} [exclude]
|
|
7
|
+
* @property {Parameters<CreateFilter>[0]} [include]
|
|
8
|
+
* @property {string[]} [loadedPaths]
|
|
9
|
+
* @property {SassCompiler} [runtime]
|
|
10
|
+
* @property {boolean} [sourceMap]
|
|
11
|
+
* @property {SassOptions} [sassOptions]
|
|
12
|
+
* @property {BundleOptions} [bundleOptions]
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} BundleOptions
|
|
17
|
+
* @property {boolean} [enabled]
|
|
18
|
+
* @property {Parameters<CreateFilter>[1]} [exclude]
|
|
19
|
+
* @property {Parameters<CreateFilter>[0]} [include]
|
|
20
|
+
* @property {string} [name]
|
|
21
|
+
* @property {string} [fileName]
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** @typedef {({ bundle: { [id: string]: string } })} SassPluginState */
|
|
25
|
+
|
|
26
|
+
/** @typedef {typeof createFilter} CreateFilter */
|
|
27
|
+
|
|
28
|
+
/** @typedef {Pick<import('sass').Compiler, 'compileString'>} SassCompiler */
|
|
29
|
+
/** @typedef {import('sass').StringOptions<'sync'>} SassOptions */
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {SassPluginOptions} options
|
|
33
|
+
* @returns {import('rollup').Plugin}
|
|
34
|
+
*/
|
|
35
|
+
export default async function (options = {}) {
|
|
36
|
+
/** @type {SassPluginState} */
|
|
37
|
+
const state = {
|
|
38
|
+
bundle: {}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** @type {SassCompiler} */
|
|
42
|
+
const runtime = options.runtime || (await import('sass'));
|
|
43
|
+
|
|
44
|
+
const bundleOptions = options.bundleOptions;
|
|
45
|
+
|
|
46
|
+
const defaultInclude = ['**/*.scss', '**/*.sass'];
|
|
47
|
+
const defaultBundleInclude = ['**/*.css', ...defaultInclude];
|
|
48
|
+
|
|
49
|
+
const filter = createFilter(options.include || defaultInclude, options.exclude);
|
|
50
|
+
const bundleFilter = bundleOptions?.enabled
|
|
51
|
+
? createFilter(bundleOptions?.include || defaultBundleInclude, bundleOptions?.exclude)
|
|
52
|
+
: undefined;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string} code
|
|
56
|
+
* @param {string} id
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
function bundleFile(code, id) {
|
|
60
|
+
if (!bundleOptions?.enabled || !bundleFilter?.(id)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
state.bundle[id] = code;
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
name: 'rollup-sass-transform',
|
|
70
|
+
transform(code, id) {
|
|
71
|
+
if (!filter(id)) {
|
|
72
|
+
return bundleFile(code, id);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const paths = [dirname(id), process.cwd()];
|
|
76
|
+
|
|
77
|
+
const result = runtime.compileString(code, {
|
|
78
|
+
loadPaths: [...paths, ...(options.loadedPaths || [])],
|
|
79
|
+
style: 'compressed',
|
|
80
|
+
sourceMap: options.sourceMap,
|
|
81
|
+
...(options.sassOptions || {})
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
bundleFile(result.css, id);
|
|
85
|
+
|
|
86
|
+
if (process.env.ROLLUP_WATCH) {
|
|
87
|
+
for (const loadedUrl of result.loadedUrls) {
|
|
88
|
+
this.addWatchFile(loadedUrl.filePath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (bundleOptions?.enabled) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
code: result.css,
|
|
98
|
+
map: result.sourceMap
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
generateBundle(rollupOptions, bundle, isWrite) {
|
|
102
|
+
if (!isWrite || !bundleOptions?.enabled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const source = Object.values(state.bundle).join('');
|
|
107
|
+
this.emitFile({
|
|
108
|
+
type: 'asset',
|
|
109
|
+
source: source,
|
|
110
|
+
name: bundleOptions.name,
|
|
111
|
+
fileName: bundleOptions.fileName
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
type: 'asset',
|
|
116
|
+
source: source
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rollup-plugin-sass-bundle",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple rollup plugin for transpile sass and bundle and output a single file",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"rollup",
|
|
14
|
+
"sass",
|
|
15
|
+
"rollup-plugin",
|
|
16
|
+
"css",
|
|
17
|
+
"scss"
|
|
18
|
+
],
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Vangel",
|
|
21
|
+
"email": "traykovski5@gmail.com"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"index.js"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@rollup/pluginutils": "^5.1.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"sass": "^1.79.4"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"sass": "> 1.45.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"sass": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|