Skip to content

Commit

Permalink
fix: build issues (#35)
Browse files Browse the repository at this point in the history
* Set public path

* Remove peer deps from fix storybook package

* try parsing all css

* Add font loader to storybook webpack

* Add change

* build before lint

* Setup node berfore pnpm

* Revert setup order

* update test

* add change
  • Loading branch information
ehyland authored Dec 21, 2021
1 parent 5324aa3 commit e6ac8c5
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 2,006 deletions.
8 changes: 8 additions & 0 deletions .changeset/two-pears-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'bgdk': patch
'@bgdk/storybook': patch
'bgdk-basic-example': patch
'create-bgdk': patch
---

fix: set public path in webpack config
8 changes: 8 additions & 0 deletions .changeset/warm-trains-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'bgdk': patch
'@bgdk/storybook': patch
'bgdk-basic-example': patch
'create-bgdk': patch
---

fix: storybook webpack config asset loading
2 changes: 1 addition & 1 deletion .github/actions/setup-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- uses: pnpm/action-setup@v2.0.1
with:
version: 6.23.6
version: '6.24.2'

- uses: actions/setup-node@main
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

- uses: ./.github/actions/setup-project

- run: pnpm lint

- run: pnpm build

- run: pnpm lint

- uses: ./.github/actions/setup-verdaccio

- name: Switch registries
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Eamon Hyland <ehyland90@gmail.com>",
"license": "MIT",
"private": true,
"packageManager": "pnpm@6.24.1",
"packageManager": "pnpm@6.24.2",
"scripts": {
"dev": "preconstruct dev",
"test": "pnpm lint",
Expand Down
3 changes: 3 additions & 0 deletions packages/bgdk/alias/mini-css-extract-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "dist/bgdk-alias-mini-css-extract-plugin.cjs.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "dist/bgdk-alias-vanilla-extract-webpack-plugin.cjs.js"
}
6 changes: 4 additions & 2 deletions packages/bgdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"/examples/basic/.gitignore",
"!/examples/*/yarn.yaml",
"/templates/",
"/commands/"
"/commands/",
"/alias/"
],
"preconstruct": {
"entrypoints": [
"cli/index.ts",
"babel-preset/index.ts",
"commands/*.ts"
"commands/*.ts",
"alias/*.ts"
]
},
"entrypoints": [
Expand Down
1 change: 1 addition & 0 deletions packages/bgdk/src/alias/mini-css-extract-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'mini-css-extract-plugin';
2 changes: 2 additions & 0 deletions packages/bgdk/src/alias/vanilla-extract-webpack-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@vanilla-extract/webpack-plugin';
export { default } from '@vanilla-extract/webpack-plugin';
1 change: 1 addition & 0 deletions packages/bgdk/src/config/createWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function createWebpackConfig({
output: {
path: paths.dist,
filename: dev ? '[name].js' : 'static/[name].[contenthash].js',
publicPath: '/',
chunkFilename: dev
? '[name].chunk.js'
: 'static/[name].chunk.[contenthash].js',
Expand Down
22 changes: 4 additions & 18 deletions packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,10 @@
"url": "git@github.com:ehyland/bgdk.git",
"directory": "packages/storybook"
},
"peerDependencies": {
"@storybook/addon-actions": "^6.4.9",
"@storybook/addon-essentials": "^6.4.9",
"@storybook/addon-links": "^6.4.9",
"@storybook/builder-webpack5": "^6.4.9",
"@storybook/manager-webpack5": "^6.4.9",
"@storybook/react": "^6.4.9",
"@vanilla-extract/webpack-plugin": "*",
"mini-css-extract-plugin": "*"
},
"devDependencies": {
"@storybook/addon-actions": "^6.4.9",
"@storybook/addon-essentials": "^6.4.9",
"@storybook/addon-links": "^6.4.9",
"@storybook/builder-webpack5": "^6.4.9",
"@storybook/manager-webpack5": "^6.4.9",
"@storybook/react": "^6.4.9",
"@vanilla-extract/webpack-plugin": "^2.1.4",
"mini-css-extract-plugin": "^2.4.5"
"bgdk": "^0.3.2"
},
"peerDependencies": {
"bgdk": "^0.3.2"
}
}
37 changes: 26 additions & 11 deletions packages/storybook/src/fix-storybook-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
import MiniCssExtractPlugin from 'bgdk/alias/mini-css-extract-plugin';
import { VanillaExtractPlugin } from 'bgdk/alias/vanilla-extract-webpack-plugin';
import type {
Configuration,
RuleSetRule,
Expand All @@ -15,15 +15,23 @@ const srcMatchers = [src, /\.css\.ts$/, /\.vanilla\.css$/];
export function fixStorybookConfig(config: Configuration) {
const rules = config.module?.rules as RuleSetRule[];

// exclude app code from default loaders
rules.forEach((rule: RuleSetRule) => {
const previousExclude = rule.exclude || [];
const fixRuleSet = (ruleSet: RuleSetRule[]) => {
ruleSet.forEach((rule) => {
if (Array.isArray(rule.oneOf)) {
fixRuleSet(rule.oneOf);
} else {
const previousExclude = rule.exclude || [];
rule.exclude = [
...(Array.isArray(previousExclude)
? previousExclude
: [previousExclude]), // Ensure we don't clobber any existing exclusions
...srcMatchers,
];
}
});
};

rule.exclude = [
...(Array.isArray(previousExclude) ? previousExclude : [previousExclude]), // Ensure we don't clobber any existing exclusions
...srcMatchers,
];
});
fixRuleSet(rules);

// add src loader for js
rules.unshift({
Expand All @@ -35,7 +43,7 @@ export function fixStorybookConfig(config: Configuration) {

// add src loader for css
rules.unshift({
test: /\.vanilla\.css$/i,
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
Expand All @@ -48,6 +56,13 @@ export function fixStorybookConfig(config: Configuration) {
include: srcMatchers,
});

// add asset loader
rules.unshift({
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/,
type: 'asset' as any,
include: srcMatchers,
});

// add vanilla plugin
config.plugins?.push(
new VanillaExtractPlugin() as unknown as WebpackPluginInstance,
Expand Down
Loading

0 comments on commit e6ac8c5

Please sign in to comment.