Skip to content

Commit

Permalink
fix: minimize the amount of CSS assets (#882)
Browse files Browse the repository at this point in the history
12M → 2M 😬
  • Loading branch information
lidel authored May 19, 2020
1 parent 81bb860 commit 1e6f42e
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 28 deletions.
4 changes: 2 additions & 2 deletions add-on/src/landing-pages/welcome/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="welcome.css">
<link rel="stylesheet" href="../../popup/heartbeat.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/welcomePage.css">
</head>

<body class="navy bg-white sans-serif">
Expand Down
2 changes: 2 additions & 0 deletions add-on/src/landing-pages/welcome/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
/* eslint-env browser, webextensions */

require('./welcome.css')

const browser = require('webextension-polyfill')
const choo = require('choo')
const createWelcomePageStore = require('./store')
Expand Down
5 changes: 3 additions & 2 deletions add-on/src/landing-pages/welcome/welcome.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import url('../../../ui-kit/tachyons.css');
@import url('../../../ui-kit/ipfs.css');
@import url('~tachyons/css/tachyons.css');
@import url('~ipfs-css/ipfs.css');
@import url('../../popup/heartbeat.css');

#left-col {
background-image: url('../../../images/stars.png'), linear-gradient(to bottom, #041727 0%, #043b55 100%);
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/options/options.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import url('/ui-kit/tachyons.css');
@import url('/ui-kit/ipfs.css');
@import url('~tachyons/css/tachyons.css');
@import url('~ipfs-css/ipfs.css');
@import url('../pages/components/switch-toggle.css');

header {
Expand Down
3 changes: 2 additions & 1 deletion add-on/src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<title>IPFS Companion Preferences</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="options.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/optionsPage.css">
</head>
<body>
<header class="flex-l items-center pa3 bg-navy bb bw3 border-aqua tc tl-l justify-between">
Expand Down
2 changes: 2 additions & 0 deletions add-on/src/options/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
/* eslint-env browser, webextensions */

require('./options.css')

const { i18n } = require('webextension-polyfill')
const choo = require('choo')
const optionsPage = require('./page')
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/pages/components/switch-toggle.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('/ui-kit/mdc.switch.min.css');
@import url('~@material/switch/dist/mdc.switch.css');

.mdc-switch {
--mdc-theme-secondary: #3e9096 /* teal */
Expand Down
3 changes: 2 additions & 1 deletion add-on/src/pages/proxy-access-dialog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title>IPFS Companion</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="proxy-access-dialog.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/proxyAclDialog.css">
</head>

<body class="bg-snow-muted h-100">
Expand Down
2 changes: 2 additions & 0 deletions add-on/src/pages/proxy-access-dialog/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

require('./proxy-access-dialog.css')

const browser = require('webextension-polyfill')
const choo = require('choo')
const createProxyAccessDialogStore = require('./store')
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/pages/proxy-access-dialog/proxy-access-dialog.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import url('../../../ui-kit/tachyons.css');
@import url('../../../ui-kit/ipfs.css');
@import url('~tachyons/css/tachyons.css');
@import url('~ipfs-css/ipfs.css');

.hover-bg-aqua-muted:hover {
background-color: #9ad4db;
Expand Down
3 changes: 2 additions & 1 deletion add-on/src/pages/proxy-acl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title>Manage Permissions</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="proxy-acl.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/proxyAclManagerPage.css">
</head>

<body>
Expand Down
2 changes: 2 additions & 0 deletions add-on/src/pages/proxy-acl/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

require('./proxy-acl.css')

const browser = require('webextension-polyfill')
const choo = require('choo')
const AccessControl = require('../../lib/ipfs-proxy/access-control')
Expand Down
2 changes: 1 addition & 1 deletion add-on/src/pages/proxy-acl/proxy-acl.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('../../../ui-kit/tachyons.css');
@import url('~tachyons/css/tachyons.css');
@import url('../../popup/heartbeat.css');

html, body {
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/popup/browser-action/browser-action.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import url('/ui-kit/tachyons.css');
@import url('/ui-kit/ipfs.css');
@import url('~tachyons/css/tachyons.css');
@import url('~ipfs-css/ipfs.css');
@import url('../heartbeat.css');
@import url('../../pages/components/switch-toggle.css');

Expand Down
3 changes: 2 additions & 1 deletion add-on/src/popup/browser-action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="browser-action.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/browserAction.css">
</head>
<body style="width: 320px; overflow: hidden; background: white;">
<div id="root"></div>
Expand Down
2 changes: 2 additions & 0 deletions add-on/src/popup/browser-action/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
/* eslint-env browser, webextensions */

require('./browser-action.css')

const choo = require('choo')
const browserActionPage = require('./page')
const browserActionStore = require('./store')
Expand Down
3 changes: 2 additions & 1 deletion add-on/src/popup/page-action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="../browser-action/browser-action.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/browserAction.css">
</head>
<body style="width: 330px; overflow: hidden; background: white;">
<div id="root"></div>
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/popup/quick-import.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import url('../../ui-kit/tachyons.css');
@import url('../../ui-kit/ipfs.css');
@import url('~tachyons/css/tachyons.css');
@import url('~ipfs-css/ipfs.css');
@import url('heartbeat.css');

html, body, #root {
Expand Down
3 changes: 2 additions & 1 deletion add-on/src/popup/quick-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="quick-import.css">
<link rel="stylesheet" href="/dist/bundles/uiCommons.css">
<link rel="stylesheet" href="/dist/bundles/importPage.css">
</head>

<body>
Expand Down
2 changes: 2 additions & 0 deletions add-on/src/popup/quick-import.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
/* eslint-env browser, webextensions */

require('./quick-import.css')

const browser = require('webextension-polyfill')
const choo = require('choo')
const html = require('choo/html')
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
"build": "run-s clean build:*",
"build:copy": "run-s build:copy:*",
"build:copy:src": "shx mkdir -p add-on/dist && shx cp -R add-on/src/* add-on/dist",
"build:copy:ui-kit": "run-s build:copy:ui-kit:*",
"build:copy:ui-kit:ipfs-css": "run-s build:copy:ui-kit:ipfs-css:*",
"build:copy:ui-kit:ipfs-css:css": "shx mkdir -p add-on/ui-kit && shx cp node_modules/ipfs-css/ipfs.css node_modules/@material/switch/dist/mdc.switch.min.css add-on/ui-kit",
"build:copy:ui-kit:ipfs-css:fonts": "shx mkdir -p add-on/ui-kit/fonts && shx cp node_modules/ipfs-css/fonts/* add-on/ui-kit/fonts",
"build:copy:ui-kit:ipfs-css:icons": "shx mkdir -p add-on/ui-kit/icons && shx cp node_modules/ipfs-css/icons/* add-on/ui-kit/icons",
"build:copy:ui-kit:tachyons": "shx mkdir -p add-on/ui-kit && shx cp node_modules/tachyons/css/tachyons.css add-on/ui-kit",
"build:js": "run-s build:js:*",
"build:js:webpack": "webpack -p",
"build:minimize-dist": "shx rm -rf add-on/dist/lib add-on/dist/contentScripts/ add-on/dist/bundles/ipfsProxyContentScriptPayload.bundle.js",
Expand Down Expand Up @@ -89,16 +83,20 @@
"babel-plugin-syntax-async-generators": "6.13.0",
"chai": "4.2.0",
"cross-env": "6.0.3",
"css-loader": "3.5.3",
"download-cli": "1.1.1",
"fakefile": "0.0.9",
"file-loader": "6.0.0",
"firefox-addons-add-update-version": "1.0.1",
"fs-promise": "2.0.3",
"get-firefox": "3.0.0",
"husky": "3.1.0",
"ignore-loader": "0.1.2",
"ignore-styles": "5.0.1",
"ipfs-or-gateway": "2.1.0",
"json": "9.0.6",
"mem-storage-area": "1.0.3",
"mini-css-extract-plugin": "0.9.0",
"mocha": "6.2.2",
"npm-run-all": "4.1.5",
"nyc": "14.1.1",
Expand All @@ -109,6 +107,7 @@
"sinon": "7.5.0",
"sinon-chrome": "3.0.1",
"standard": "14.3.1",
"style-loader": "1.2.1",
"tar": "5.0.5",
"terser": "4.6.7",
"terser-webpack-plugin": "2.3.5",
Expand Down
28 changes: 28 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const webpack = require('webpack')
const merge = require('webpack-merge')
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

Expand Down Expand Up @@ -33,6 +34,9 @@ const commonConfig = {
},
// plugins: [new BundleAnalyzerPlugin()]
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new SimpleProgressWebpackPlugin({
format: process.env.CI ? 'expanded' : 'minimal'
}),
Expand All @@ -47,6 +51,30 @@ const commonConfig = {
],
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development'
}
},
'css-loader'
]
},
{
test: /\.(png|jpe?g|gif|svg|eot|otf|ttf|woff|woff2)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
},
{
// Ignore legacy fonts (both Firefox and Chromium talk WOFF2)
test: /\.(otf|eot|ttf|woff)(\?.*$|$)/,
use: ['raw-loader', 'ignore-loader']
},
{
exclude: /node_modules/,
test: /\.js$/,
Expand Down
Loading

0 comments on commit 1e6f42e

Please sign in to comment.