Skip to content

Commit e5dc2ad

Browse files
committed
Show styles in Storybook
1 parent dca7867 commit e5dc2ad

File tree

5 files changed

+141
-30
lines changed

5 files changed

+141
-30
lines changed

.storybook/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path');
2+
13
module.exports = {
24
stories: ['../stories/**/*.stories.(ts|tsx)'],
35
addons: [
@@ -22,6 +24,17 @@ module.exports = {
2224
],
2325
});
2426

27+
// Remove the existing css rule
28+
config.module.rules = config.module.rules.filter(
29+
f => f.test.toString() !== '/\\.css$/'
30+
);
31+
32+
config.module.rules.push({
33+
test: /\.css$/,
34+
use: ['style-loader', 'css-loader'],
35+
include: path.resolve(__dirname, '../src'),
36+
});
37+
2538
config.resolve.extensions.push('.ts', '.tsx');
2639

2740
return config;

example/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'react-app-polyfill/ie11';
22
import * as React from 'react';
33
import * as ReactDOM from 'react-dom';
44
import { ReactTypical } from '../.';
5+
import '../dist/styles.min.css';
56

67
const App = () => {
78
const hypeText = ['Creator', 'Entrepreneur', 'Doer', 'Lone Wolf'];

package-lock.json

Lines changed: 115 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@types/react-dom": "^16.9.8",
6666
"autoprefixer": "^9.8.5",
6767
"babel-loader": "^8.1.0",
68+
"css-loader": "^4.2.1",
6869
"cssnano": "^4.1.10",
6970
"husky": "^4.2.5",
7071
"identity-obj-proxy": "^3.0.0",
@@ -73,6 +74,8 @@
7374
"react-dom": "^16.13.1",
7475
"react-is": "^16.13.1",
7576
"rollup-plugin-postcss": "^3.1.3",
77+
"rollup-plugin-terser": "^6.1.0",
78+
"style-loader": "^1.2.1",
7679
"ts-loader": "^8.0.1",
7780
"tsdx": "^0.13.2",
7881
"tslib": "^2.0.0",

tsdx.config.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
const path = require('path');
12
const postcss = require('rollup-plugin-postcss');
3+
const { terser } = require('rollup-plugin-terser');
24
const autoprefixer = require('autoprefixer');
35
const cssnano = require('cssnano');
46

@@ -7,6 +9,8 @@ module.exports = {
79
config.plugins.push(
810
postcss({
911
modules: true,
12+
onlyModules: true,
13+
autoModules: false,
1014
plugins: [
1115
autoprefixer(),
1216
cssnano({
@@ -15,8 +19,11 @@ module.exports = {
1519
],
1620
inject: false,
1721
// only write out CSS for the first bundle (avoids pointless extra files):
18-
extract: !!options.writeMeta,
19-
})
22+
// extract: !!options.writeMeta,
23+
extract: path.resolve('dist/styles.min.css'),
24+
minimize: true,
25+
}),
26+
terser()
2027
);
2128
return config;
2229
},

0 commit comments

Comments
 (0)