Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: css styles applied & config page collapse #112

Merged
merged 7 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"css-loader": "^6.10.0",
"eslint-config-standard-with-typescript": "^34.0.1",
"html-webpack-plugin": "^5.5.0",
"mini-css-extract-plugin": "^2.8.1",
"npm-run-all": "^4.1.5",
"patch-package": "^6.5.1",
"rimraf": "^4.4.1",
Expand All @@ -66,5 +67,7 @@
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.8.0"
},
"sideEffects": false
"sideEffects": [
"*.css"
]
Comment on lines +70 to +72
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed this to tell webpack about our css (tree splitting was ignoring css files because we told it we had no side effects..).

IIUC this is a webpack specific thing. see https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

}
4 changes: 3 additions & 1 deletion src/components/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ export default (): JSX.Element | null => {
return null
}

const isInIframe = window.self !== window.top

return (
<main className='pa4-l bg-snow mw7 center pa4'>
<Collapsible collapsedLabel="View config" expandedLabel='Hide config' collapsed={true}>
<Collapsible collapsedLabel="View config" expandedLabel='Hide config' collapsed={isInIframe}>
<LocalStorageInput localStorageKey={LOCAL_STORAGE_KEYS.config.gateways} label='Gateways' validationFn={urlValidationFn} defaultValue='[]' />
<LocalStorageInput localStorageKey={LOCAL_STORAGE_KEYS.config.routers} label='Routers' validationFn={urlValidationFn} defaultValue='[]'/>
<LocalStorageToggle localStorageKey={LOCAL_STORAGE_KEYS.config.autoReload} onLabel='Auto Reload' offLabel='Show Config' />
Expand Down
9 changes: 8 additions & 1 deletion test/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
import { constants } from 'node:fs'
import { access } from 'node:fs/promises'
import { access, readFile } from 'node:fs/promises'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { expect } from 'aegir/chai'
Expand All @@ -14,4 +14,11 @@ describe('verify-dist', async () => {
*/
await expect(access(resolve(cwd, '../dist/ipfs-sw-sw.js'), constants.F_OK)).to.not.be.rejected()
})

it('has css file with expected content', async () => {
await expect(access(resolve(cwd, '../dist/ipfs-sw-styles.css'), constants.F_OK)).to.not.be.rejected()
const contents = await readFile(resolve(cwd, '../dist/ipfs-sw-styles.css'), 'utf8')
expect(contents).to.include('47vh')
expect(contents).to.include('.local-storage-toggle input.status')
})
Comment on lines +18 to +23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will likely want to remove this in the future but i'm going to leave it for now

})
24 changes: 22 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path'
import { fileURLToPath } from 'node:url'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import webpack from 'webpack'
import BundleAnalyzerPlugin from 'webpack-bundle-analyzer'
Expand All @@ -21,6 +22,13 @@ const splitChunks = {
priority: -10,
chunks: 'all'
},
styles: {
minChunks: 1,
name: 'styles',
type: 'css/mini-extract',
chunks: 'initial',
enforce: true
},
sw: {
test: /[\\/]src[\\/]sw.ts/,
name: 'sw',
Expand Down Expand Up @@ -203,6 +211,11 @@ const common = {

new webpack.DefinePlugin({
window: 'globalThis' // attempt to naively replace all "window" keywords with "globalThis"
}),

new MiniCssExtractPlugin({
filename: 'ipfs-sw-[name].css',
chunkFilename: 'ipfs-sw-[id].css'
})
],

Expand Down Expand Up @@ -237,8 +250,15 @@ const common = {

// Fonts and SVGs: Inline files
{ test: /\.(woff(2)?|eot|ttf|otf|svg|)$/, type: 'asset/inline' },

{ test: /\.(css)$/, use: ['style-loader', 'css-loader'] }
{
// If you enable `experiments.css` or `experiments.futureDefaults`, please uncomment line below
// type: 'javascript/auto',
test: /\.(sa|sc|c)ss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
}
]
},

Expand Down
Loading