Skip to content

Commit

Permalink
fix: css style lose
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Jan 21, 2024
1 parent 23d7fb2 commit 5f98362
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/cursor_manager/cursor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/suika/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
// vite does not automatically import styles when referencing other packages, you need to manually import them
import '@suika/core/dist/style.css';
import '@suika/components/dist/style.css';

// vite does not automatically import styles when referencing other packages, you need to manually import them
// TODO: FIXME: find a better way to do this
Expand Down
27 changes: 24 additions & 3 deletions scripts/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { context } = require('esbuild');
const args = require('minimist')(process.argv.slice(2));
const path = require('path');
const { sassPlugin } = require('esbuild-sass-plugin');
const fs = require('fs');

const setup = async () => {
const target = args._[0];
Expand All @@ -28,6 +29,7 @@ const setup = async () => {
],
outfile,
bundle: true,
metafile: true,
external: Object.keys({
...pkgJson.dependencies,
...pkgJson.peerDependencies,
Expand All @@ -38,16 +40,35 @@ const setup = async () => {
platform: 'browser',
plugins: [
sassPlugin({
type: 'style',
type: 'css',
}),
{
name: 'watch-build',
setup(build) {
build.onEnd((result) => {
if (result.errors.length) {
console.error('build failed:', result.errors);
} else {
console.log('watch build succeeded:', relativeOutputFile);
return;
}
console.log('watch build succeeded:', relativeOutputFile);

// rename output CSS file
if (result.metafile) {
const outputs = result.metafile.outputs;
Object.keys(outputs).forEach((output) => {
const oldPath = path.resolve(output);
let newPath;
if (output.endsWith('.css')) {
// <target>.es.css ---> style.css
newPath = oldPath.replace(
`dist/${target}.es.css`,
'dist/style.css',
);
}
if (newPath && oldPath !== newPath) {
fs.renameSync(oldPath, newPath);
}
});
}
});
},
Expand Down

0 comments on commit 5f98362

Please sign in to comment.