Skip to content

Commit

Permalink
perf: extract css
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Feb 8, 2024
1 parent 5a53a7b commit 27b5688
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tests/clover*.xml
node_modules/

/js
/css

# packaged app
build/artifacts
Expand Down
21 changes: 12 additions & 9 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"jest-serializer-vue": "^3.1.0",
"jest-transform-stub": "^2.0.0",
"jest-watch-typeahead": "^2.2.2",
"mini-css-extract-plugin": "^2.8.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"postcss": "^8.4.31",
"postcss-loader": "^4.3.0",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/html-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

// injected styles
import '../css/html-response.css'
import './css/html-response.css'

// iframe-resizer client script
import 'iframe-resizer/js/iframeResizer.contentWindow.js'
Expand Down
4 changes: 2 additions & 2 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { NcContent } from '@nextcloud/vue'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
import '../../css/mail.scss'
import '../../css/mobile.scss'
import '../css/mail.scss'
import '../css/mobile.scss'
import { testAccountConnection } from '../service/AccountService.js'
import logger from '../logger.js'
Expand Down
1 change: 1 addition & 0 deletions templates/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
*/
script('mail', 'mail');
style('mail', 'mail');
?>

<input type="hidden" id="attachment-size-limit" value="<?php p($_['attachment-size-limit']); ?>">
Expand Down
1 change: 1 addition & 0 deletions templates/oauth_done.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

script(\OCA\Mail\AppInfo\Application::APP_ID, 'oauthpopup');
style('mail', 'oauthpopup');

?>

Expand Down
1 change: 1 addition & 0 deletions templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

script(\OCA\Mail\AppInfo\Application::APP_ID, 'settings');
style('mail', 'settings');

?>
<div id="mail-admin-settings">
Expand Down
30 changes: 28 additions & 2 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
const path = require('path')
const fs = require('fs/promises')
const { existsSync } = require('fs')
const CKEditorWebpackPlugin = require('@ckeditor/ckeditor5-dev-webpack-plugin')
const { styles } = require('@ckeditor/ckeditor5-dev-utils')
const { VueLoaderPlugin } = require('vue-loader')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const { ProvidePlugin } = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

const CleanCssPlugin = {
apply(compiler) {
compiler.hooks.emit.tapAsync('CleanCss', async (compilation, callback) => {
const directory = path.join(__dirname, 'css')
if (!existsSync(directory)) {
callback()
return
}

for (const file of await fs.readdir(directory)) {
await fs.unlink(path.join(directory, file))
}

callback()
})
},
}

function getPostCssConfig(ckEditorOpts) {
// CKEditor is not compatbile with postcss@8 and postcss-loader@4 despite stating so.
Expand All @@ -13,6 +34,10 @@ function getPostCssConfig(ckEditorOpts) {
};

const plugins = [
new MiniCssExtractPlugin({
filename: '../css/[name].css',
chunkFilename: '../css/mail.[name].[contenthash].css',
}),
// CKEditor needs its own plugin to be built using webpack.
new CKEditorWebpackPlugin({
// See https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
Expand All @@ -25,6 +50,7 @@ const plugins = [
// Thanks to https://stackoverflow.com/a/65018686/14239942
process: 'process/browser.js',
}),
CleanCssPlugin,
]

module.exports = {
Expand All @@ -45,11 +71,11 @@ module.exports = {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.vue$/,
Expand Down

0 comments on commit 27b5688

Please sign in to comment.