Skip to content

Commit 7a389b2

Browse files
authored
Optimise generated CSS (#195)
* Optimise generated css * remove space * Exclude calc from the css optimisations
1 parent 137977a commit 7a389b2

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"loader-utils": "1.1.0",
126126
"log-symbols": "2.1.0",
127127
"log-update": "2.3.0",
128+
"optimize-css-assets-webpack-plugin": "3.2.0",
128129
"ora": "1.3.0",
129130
"pkg-dir": "2.0.0",
130131
"postcss-import": "12.0.0",

src/base.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const postcssImport = require('postcss-import');
1717
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
1818
const slash = require('slash');
1919
const WrapperPlugin = require('wrapper-webpack-plugin');
20+
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
2021

2122
const basePath = process.cwd();
2223
const srcPath = path.join(basePath, 'src');
@@ -324,6 +325,12 @@ export default function webpackConfigFactory(args: any): WebpackConfiguration {
324325
filename: 'main.css',
325326
allChunks: true
326327
}),
328+
new OptimizeCssAssetsPlugin({
329+
cssProcessor: require('cssnano'),
330+
cssProcessorPluginOptions: {
331+
preset: ['default', { calc: false }]
332+
}
333+
}),
327334
new webpack.NamedChunksPlugin(),
328335
new webpack.NamedModulesPlugin(),
329336
(args.externals || isTest) &&

tests/integration/build.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ Currently Rendered by BTR: false`
4343
it('correctly inlines and resolves external variables for legacy builds', () => {
4444
cy.request('/test-app/output/dev-app/main.css').then((response) => {
4545
const css = response.body;
46-
expect(css).to.contain('color: var(--foreground-color);');
47-
expect(css).to.contain('color: blue;');
48-
expect(css).to.contain('color: var(--primary);');
49-
expect(css).to.contain('color: red;');
46+
expect(css).to.contain('color:var(--foreground-color);');
47+
expect(css).to.contain('color:blue;');
48+
expect(css).to.contain('color:var(--primary);');
49+
expect(css).to.contain('color:red;');
5050
});
5151
});
5252
it('correctly inlines and resolves external variables for evergreen builds', () => {
5353
cy.request('/test-app/output/dev-app-evergreen/main.css').then((response) => {
5454
const css = response.body;
55-
expect(css).to.contain('color: var(--foreground-color);');
56-
expect(css).to.contain('color: blue;');
57-
expect(css).to.contain('color: var(--primary);');
58-
expect(css).to.contain('color: red;');
55+
expect(css).to.contain('color:var(--foreground-color);');
56+
expect(css).to.contain('color:blue;');
57+
expect(css).to.contain('color:var(--primary);');
58+
expect(css).to.contain('color:red;');
5959
});
6060
});
6161
});

0 commit comments

Comments
 (0)