@react5/bundle-sass 0.5.2
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/README.md +16 -0
- package/index.js +111 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 react5
|
|
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/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# bundle-sass
|
|
2
|
+
A rollup plugin to bundle Sass, SCSS, and CSS files and apply PostCSS processing.
|
|
3
|
+
|
|
4
|
+
## Usage in Rollup
|
|
5
|
+
```javascript
|
|
6
|
+
plugins: [
|
|
7
|
+
...
|
|
8
|
+
bundleSass({
|
|
9
|
+
copyFonts: true,
|
|
10
|
+
postfixOptions: {
|
|
11
|
+
plugins: [],
|
|
12
|
+
use: []
|
|
13
|
+
}
|
|
14
|
+
...
|
|
15
|
+
]
|
|
16
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import postcss from 'postcss';
|
|
4
|
+
import { compileString } from 'sass-embedded';
|
|
5
|
+
|
|
6
|
+
function getFilePriority(fileName) {
|
|
7
|
+
if (fileName.includes('themes')) return 0;
|
|
8
|
+
if (fileName.includes('design-system')) return 1;
|
|
9
|
+
return 2;
|
|
10
|
+
}
|
|
11
|
+
function compareFiles(a, b) {
|
|
12
|
+
const priorityDiff = getFilePriority(a.id) - getFilePriority(b.id);
|
|
13
|
+
if (priorityDiff !== 0) {
|
|
14
|
+
return priorityDiff;
|
|
15
|
+
}
|
|
16
|
+
return a.id.localeCompare(b.id);
|
|
17
|
+
}
|
|
18
|
+
function copyFontFolders(emitFile) {
|
|
19
|
+
return async function (fontImport) {
|
|
20
|
+
const fontDir = path.join(path.dirname(fontImport.id), 'files');
|
|
21
|
+
const fontFiles = await fs.readdir(fontDir);
|
|
22
|
+
|
|
23
|
+
await Promise.all(fontFiles.map(async file => {
|
|
24
|
+
const filePath = path.join(fontDir, file);
|
|
25
|
+
emitFile({
|
|
26
|
+
type: 'asset',
|
|
27
|
+
fileName: path.join(path.basename(fontDir), file),
|
|
28
|
+
source: await fs.readFile(filePath)
|
|
29
|
+
});
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default function bundleSass({ output, noOutput = false, copyFonts = false, exclusive = true, scssOnly = false, postfixOptions = {} } = {}) {
|
|
35
|
+
const files = new Set();
|
|
36
|
+
const bundleExt = "scss";
|
|
37
|
+
const {
|
|
38
|
+
plugins = [],
|
|
39
|
+
use = [],
|
|
40
|
+
} = postfixOptions;
|
|
41
|
+
return {
|
|
42
|
+
name: 'bundle-sass',
|
|
43
|
+
transform(source, id) {
|
|
44
|
+
if (/\.s?[ac]ss$/.test(id)) {
|
|
45
|
+
if (/\.sass$/.test(id)) {
|
|
46
|
+
bundleExt = "sass";
|
|
47
|
+
}
|
|
48
|
+
files.add({ id, content: source });
|
|
49
|
+
if (exclusive) {
|
|
50
|
+
return { code: `export default ${JSON.stringify(source)}` };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
},
|
|
55
|
+
async generateBundle(opts) {
|
|
56
|
+
if (noOutput) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const outputName = output || `${opts.file ? path.parse(opts.file).name : 'index'}.${bundleExt}`;
|
|
60
|
+
|
|
61
|
+
const outputPath = path.resolve(
|
|
62
|
+
opts.file ? path.dirname(opts.file) : opts.dir,
|
|
63
|
+
outputName,
|
|
64
|
+
);
|
|
65
|
+
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
66
|
+
|
|
67
|
+
const uniqueFiles = Array.from(files).sort(compareFiles);
|
|
68
|
+
|
|
69
|
+
const scssDeclarations = `@use 'sass:color';\n`;
|
|
70
|
+
const bundledContent = scssDeclarations
|
|
71
|
+
+ use.join('\n')
|
|
72
|
+
+ uniqueFiles.map((file) => file.content).join('\n');
|
|
73
|
+
//await fs.writeFile(outputPath, bundledContent);
|
|
74
|
+
this.emitFile({
|
|
75
|
+
type: 'asset',
|
|
76
|
+
fileName: outputName,
|
|
77
|
+
source: bundledContent
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (scssOnly) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (copyFonts) {
|
|
85
|
+
const fontSourceFiles = uniqueFiles.filter((file) => file.id.includes("@fontsource"));
|
|
86
|
+
await Promise.all(fontSourceFiles.map(copyFontFolders(this.emitFile)));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const cssResult = await compileString(bundledContent, {});
|
|
90
|
+
|
|
91
|
+
const outputName2 = `${outputName.replace(/\.s?[ac]ss$/, '.css')}`;
|
|
92
|
+
|
|
93
|
+
const validPlugins = plugins.filter(Boolean);
|
|
94
|
+
const r = await postcss(validPlugins)
|
|
95
|
+
.process(cssResult.css);
|
|
96
|
+
|
|
97
|
+
this.emitFile({
|
|
98
|
+
type: 'asset',
|
|
99
|
+
fileName: outputName2,
|
|
100
|
+
source: r.css
|
|
101
|
+
});
|
|
102
|
+
if (r.map) {
|
|
103
|
+
this.emitFile({
|
|
104
|
+
type: 'asset',
|
|
105
|
+
fileName: `${outputName2}.map`,
|
|
106
|
+
source: r.map.toString()
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react5/bundle-sass",
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "A rollup plugin to bundle sass, scss, css files and apply postcss processing.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rollup",
|
|
7
|
+
"scss",
|
|
8
|
+
"sass",
|
|
9
|
+
"css",
|
|
10
|
+
"rollup plugin"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"postcss": "^8.5.1",
|
|
14
|
+
"sass-embedded": "^1.83.4"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git@github.com:react5com/bundle-sass.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "react5",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "index.js",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
26
|
+
}
|
|
27
|
+
}
|