Skip to content

Commit b51e00f

Browse files
authored
add svgo and imageoptim (codesandbox#2440)
* add svgo and imageoptim * cleanup
1 parent defea08 commit b51e00f

File tree

4 files changed

+229
-12
lines changed

4 files changed

+229
-12
lines changed

packages/app/config/webpack.common.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable global-require */
12
const webpack = require('webpack');
23
const path = require('path');
34
const fs = require('fs');
@@ -336,7 +337,19 @@ module.exports = {
336337
// When you `import` an asset, you get its (virtual) filename.
337338
// In production, they would get copied to the `build` folder.
338339
{
339-
test: /\.(ico|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
340+
test: /\.(svg)(\?.*)?$/,
341+
use: [
342+
{
343+
loader: 'file-loader',
344+
options: {
345+
name: 'static/media/[name].[hash:8].[ext]',
346+
},
347+
},
348+
{ loader: 'svgo-loader' },
349+
],
350+
},
351+
{
352+
test: /\.(ico|jpg|png|gif|eot|otf|webp|ttf|woff|woff2)(\?.*)?$/,
340353
exclude: [/\/favicon.ico$/],
341354
loader: 'file-loader',
342355
options: {

packages/app/config/webpack.prod.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
1+
/* eslint-disable global-require */
2+
3+
// const SentryWebpackPlugin = require('@sentry/webpack-plugin');
24
const merge = require('webpack-merge');
35
const webpack = require('webpack');
6+
const ImageminPlugin = require('imagemin-webpack-plugin').default;
47
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
58
const TerserJSPlugin = require('terser-webpack-plugin');
69
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
@@ -10,15 +13,15 @@ const normalizeName = require('webpack/lib/optimize/SplitChunksPlugin')
1013
const ManifestPlugin = require('webpack-manifest-plugin');
1114
const CopyWebpackPlugin = require('copy-webpack-plugin');
1215
const VERSION = require('@codesandbox/common/lib/version').default;
13-
const childProcess = require('child_process');
16+
// const childProcess = require('child_process');
1417
const commonConfig = require('./webpack.common');
1518

1619
const publicPath = '/';
17-
const isMaster =
18-
childProcess
19-
.execSync(`git branch | grep \\* | cut -d ' ' -f2`)
20-
.toString()
21-
.trim() === 'master';
20+
// const isMaster =
21+
// childProcess
22+
// .execSync(`git branch | grep \\* | cut -d ' ' -f2`)
23+
// .toString()
24+
// .trim() === 'master';
2225

2326
const normalize = normalizeName({ name: true, automaticNameDelimiter: '~' });
2427

@@ -128,6 +131,7 @@ module.exports = merge(commonConfig, {
128131
// https://github.com/facebookincubator/create-react-app/issues/2612
129132
return;
130133
}
134+
// eslint-disable-next-line no-console
131135
console.log(message);
132136
},
133137
minify: true,
@@ -219,6 +223,7 @@ module.exports = merge(commonConfig, {
219223
// https://github.com/facebookincubator/create-react-app/issues/2612
220224
return;
221225
}
226+
// eslint-disable-next-line no-console
222227
console.log(message);
223228
},
224229
minify: true,
@@ -349,6 +354,11 @@ module.exports = merge(commonConfig, {
349354
to: 'public/sse-hooks',
350355
},
351356
]),
357+
new ImageminPlugin({
358+
pngquant: {
359+
quality: '95-100',
360+
},
361+
}),
352362
// isMaster &&
353363
// new SentryWebpackPlugin({
354364
// include: 'src',

packages/app/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
"html-loader": "^0.5.5",
268268
"html-webpack-plugin": "^4.0.0-beta.1",
269269
"http-proxy-middleware": "^0.17.3",
270+
"imagemin-webpack-plugin": "^2.4.2",
270271
"jest": "^24.8.0",
271272
"jest-image-snapshot": "^1.0.1",
272273
"jest-junit": "^3.4.1",
@@ -293,6 +294,8 @@
293294
"selenium-webdriver": "^4.0.0-alpha.1",
294295
"strip-ansi": "3.0.1",
295296
"style-loader": "^0.21.0",
297+
"svgo": "^1.3.0",
298+
"svgo-loader": "^2.2.1",
296299
"sw-precache-webpack-plugin": "^0.11.5",
297300
"terser": "^4.1.4",
298301
"terser-webpack-plugin": "^1.4.1",

0 commit comments

Comments
 (0)