Skip to content

Commit c7d06d1

Browse files
committed
🎉 Initial commit.
0 parents  commit c7d06d1

9 files changed

Lines changed: 198 additions & 0 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
build/
3+
dist/
4+
package-lock.json
5+
*.lock
6+
*.log.*
7+
*.log
8+
*.tgz

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
build/
3+
src/
4+
package-lock.json
5+
*.lock
6+
*.log.*
7+
*.log
8+
*.tgz

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019- RequireX authors
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.
22+

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# requirex-postcss-bundle
2+
3+
This is a minified bundle of the following npm packages to allow importing them faster from [requirex](https://github.com/requirex/requirex#readme):
4+
5+
- [postcss](https://github.com/postcss/postcss)
6+
- [postcss-safe-parser](https://github.com/postcss/postcss-safe-parser)
7+
- [postcss-import](https://github.com/postcss/postcss-import)
8+
- [postcss-url](https://github.com/postcss/postcss-url)
9+
- [autoprefixer](https://github.com/postcss/autoprefixer)
10+
- [cssnano](https://github.com/cssnano/cssnano)
11+
12+
# License
13+
14+
For the small amount of code this package contributes, the following applies:
15+
16+
[The MIT License](https://raw.githubusercontent.com/requirex/requirex-postcss-bundle/master/LICENSE)
17+
18+
Copyright (c) 2019- RequireX authors.
19+
20+
The included minified packages remain under their respective licenses.

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "requirex-postcss-bundle",
3+
"version": "0.0.1",
4+
"description": "PostCSS bundled for requirex",
5+
"main": "dist/index.min.js",
6+
"scripts": {
7+
"tsc": "tsc",
8+
"prepublish": "node src/build.js src/index.ts > build/index.js && tsc -p src && tsc --allowJs -m commonjs --outDir dist build/index.js && uglifyjs -c -m < dist/index.js > dist/index.min.js"
9+
},
10+
"author": "Juha Järvi",
11+
"license": "MIT",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/requirex/requirex-postcss-bundle.git"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/requirex/requirex-postcss-bundle/issues"
18+
},
19+
"homepage": "https://github.com/requirex/requirex-postcss-bundle#readme",
20+
"devDependencies": {
21+
"@types/autoprefixer": "^9.5.0",
22+
"@types/cssnano": "^4.0.0",
23+
"@types/postcss-url": "^8.0.1",
24+
"autoprefixer": "^9.5.1",
25+
"cssnano": "^4.1.10",
26+
"postcss": "^7.0.16",
27+
"postcss-import": "^12.0.1",
28+
"postcss-safe-parser": "^4.0.1",
29+
"postcss-url": "^8.0.0",
30+
"requirex": "^0.1.2",
31+
"safe-buffer": "^5.1.2",
32+
"string_decoder": "^1.2.0",
33+
"sugarss": "^2.0.0",
34+
"typescript": "^3.5.2",
35+
"uglify-js": "^3.6.0"
36+
}
37+
}

src/build.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require('requirex');
2+
3+
System.build(require('path').resolve(process.argv[2])).then(function(code) {
4+
process.stdout.write(code);
5+
});

src/index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as postcss from 'postcss';
2+
import * as safeParser from 'postcss-safe-parser';
3+
import * as autoprefixer from 'autoprefixer';
4+
import * as cssnano from 'cssnano';
5+
import * as atImport from 'postcss-import';
6+
import * as atUrl from 'postcss-url';
7+
8+
// Ensure custom URL resolution support gets bundled.
9+
import('postcss-url/src/type/custom');
10+
11+
export interface PostConfig {
12+
importResolve: (key: string, dir: string) => string | Promise<string>;
13+
importLoad: (key: string) => string | Promise<string>;
14+
urlResolve: (key: string, isLocal: boolean) => string;
15+
minify?: boolean;
16+
}
17+
18+
export class PostBuilder {
19+
20+
constructor(public config: PostConfig) {
21+
if(config.minify) {
22+
this.pluginList.push(cssnano());
23+
}
24+
}
25+
26+
build(key: string, baseKey: string) {
27+
return postcss(this.pluginList).process('@import "' + key + '"', {
28+
parser: safeParser,
29+
from: baseKey,
30+
map: {
31+
inline: false,
32+
sourcesContent: false
33+
}
34+
}).then((result) => result.css);
35+
}
36+
37+
private pluginList: postcss.AcceptedPlugin[] = [
38+
atImport({
39+
resolve: this.config.importResolve,
40+
load: this.config.importLoad
41+
}),
42+
atUrl({
43+
url: ((asset) => {
44+
const isLocal = !!asset.pathname;
45+
return this.config.urlResolve(isLocal ? asset.absolutePath! : asset.url, isLocal);
46+
}) as atUrl.CustomTransformFunction
47+
}),
48+
autoprefixer
49+
];
50+
51+
}

src/postcss.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
declare module 'postcss-safe-parser' {
2+
import { Parser } from 'postcss';
3+
4+
const parser: Parser;
5+
export = parser;
6+
}
7+
8+
declare module 'postcss-import' {
9+
import { AcceptedPlugin } from 'postcss';
10+
11+
interface ImportConfig {
12+
filter?: () => boolean;
13+
root?: string;
14+
path?: string | string[];
15+
plugins?: AcceptedPlugin[];
16+
resolve?: (key: string, dir: string, config?: ImportConfig) => string | Promise<string>;
17+
load?: (key: string, config?: ImportConfig) => string | Promise<string>;
18+
skipDuplicates?: boolean;
19+
addModulesDirectories?: string[];
20+
}
21+
22+
const create: (config: ImportConfig) => AcceptedPlugin;
23+
export = create;
24+
}
25+
26+
declare module 'postcss-url/src/type/custom' {}

src/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compileOnSave": true,
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationDir": "../dist",
6+
"emitDeclarationOnly": true,
7+
"lib": [ "dom", "es5", "es2015.collection", "es2015.promise" ],
8+
"moduleResolution": "node",
9+
"noImplicitAny": true,
10+
"noImplicitThis": true,
11+
"outDir": "../dist",
12+
"removeComments": false,
13+
"strictFunctionTypes": true,
14+
"strictNullChecks": true,
15+
"target": "es5"
16+
},
17+
"files": [
18+
"postcss.d.ts",
19+
"index.ts"
20+
]
21+
}

0 commit comments

Comments
 (0)