Skip to content

Commit 374e81a

Browse files
committed
init
0 parents  commit 374e81a

File tree

10 files changed

+456
-0
lines changed

10 files changed

+456
-0
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['https://www.paypal.com/paypalme/wxsm']

.github/renovate.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": [
3+
"config:base"
4+
],
5+
"packageRules": [
6+
{
7+
"matchUpdateTypes": [
8+
"minor",
9+
"patch"
10+
],
11+
"matchCurrentVersion": "!/^0/",
12+
"automerge": true
13+
}
14+
]
15+
}

.github/workflows/publish_npm.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: publish npm
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
deploy_npm:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/setup-node@v2
13+
with:
14+
node-version: '12.x'
15+
registry-url: 'https://registry.npmjs.org'
16+
- uses: actions/checkout@v2
17+
- name: Publish NPM
18+
run: npm publish
19+
env:
20+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: publish release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
deploy_release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
ref: master
16+
- name: Changelog
17+
uses: scottbrenner/generate-changelog-action@master
18+
id: Changelog
19+
with:
20+
exclude: chore
21+
env:
22+
REPO: ${{ github.repository }}
23+
- name: Create Release
24+
id: create_release
25+
uses: actions/create-release@v1
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
with:
29+
tag_name: ${{ github.ref }}
30+
release_name: Release ${{ github.ref }}
31+
body: |
32+
${{ steps.Changelog.outputs.changelog }}
33+
draft: false
34+
prerelease: false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.idea

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# vite-plugin-libcss
2+
3+
todo

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { ResolvedConfig, PluginOption } from 'vite';
2+
3+
export default function (): PluginOption

index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fs from 'fs';
2+
import { resolve } from 'path';
3+
4+
let viteConfig;
5+
6+
export default function() {
7+
return {
8+
name: 'lib-inject-css',
9+
apply: 'build',
10+
enforce: 'post',
11+
12+
configResolved(resolvedConfig) {
13+
viteConfig = resolvedConfig;
14+
},
15+
16+
writeBundle(_, bundle) {
17+
const files = Object.keys(bundle);
18+
const cssFile = files.find((v) => v.endsWith('.css'));
19+
if (!cssFile) {
20+
return;
21+
}
22+
for (const file of files) {
23+
if (!file.endsWith('.js')) {
24+
continue;
25+
}
26+
const outDir = viteConfig.build.outDir || 'dist';
27+
const filePath = resolve(viteConfig.root, outDir, file);
28+
const data = fs.readFileSync(filePath, {
29+
encoding: 'utf8',
30+
});
31+
fs.writeFileSync(filePath, `import './${cssFile}';\n${data}`);
32+
}
33+
},
34+
};
35+
}

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "vite-plugin-libcss",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"types": "index.d.ts",
6+
"author": "wxsms@foxmail.com",
7+
"license": "MIT",
8+
"private": false,
9+
"devDependencies": {
10+
"vite": "^2.7.5"
11+
},
12+
"peerDependencies": {
13+
"vite": "^2"
14+
}
15+
}

0 commit comments

Comments
 (0)