mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
Error out if required (json) configs are missing/corrupted.
This commit is contained in:
@@ -12,19 +12,8 @@ const CopyPlugin = require('copy-webpack-plugin');
|
|||||||
const WatchTimestampsPlugin = require('./config/watch-timestamps-plugin');
|
const WatchTimestampsPlugin = require('./config/watch-timestamps-plugin');
|
||||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||||
|
|
||||||
function parseJson(text, fallback) {
|
function readJson(filename) {
|
||||||
try {
|
return JSON.parse(fs.readFileSync(filename));
|
||||||
return JSON.parse(text);
|
|
||||||
}
|
|
||||||
catch (e) { }
|
|
||||||
return fallback || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
function readFile(filename) {
|
|
||||||
try {
|
|
||||||
return fs.readFileSync(filename);
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function(_, env) {
|
module.exports = function(_, env) {
|
||||||
@@ -35,11 +24,6 @@ module.exports = function(_, env) {
|
|||||||
path.join(__dirname, 'src/routes')
|
path.join(__dirname, 'src/routes')
|
||||||
];
|
];
|
||||||
|
|
||||||
let babelRc = parseJson(readFile('.babelrc'));
|
|
||||||
babelRc.babelrc = false;
|
|
||||||
|
|
||||||
let manifest = parseJson(readFile('./src/manifest.json'));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode: env.mode || 'development',
|
mode: env.mode || 'development',
|
||||||
entry: path.join(__dirname, 'config/client-boot.js'),
|
entry: path.join(__dirname, 'config/client-boot.js'),
|
||||||
@@ -75,7 +59,7 @@ module.exports = function(_, env) {
|
|||||||
{
|
{
|
||||||
test: /\.(tsx?|jsx?)$/,
|
test: /\.(tsx?|jsx?)$/,
|
||||||
loader: 'babel-loader',
|
loader: 'babel-loader',
|
||||||
options: babelRc
|
options: Object.assign(readJson('.babelrc'), { babelrc: false })
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(scss|sass)$/,
|
test: /\.(scss|sass)$/,
|
||||||
@@ -179,7 +163,7 @@ module.exports = function(_, env) {
|
|||||||
removeStyleLinkTypeAttributes: true,
|
removeStyleLinkTypeAttributes: true,
|
||||||
removeComments: true
|
removeComments: true
|
||||||
},
|
},
|
||||||
manifest,
|
manifest: readJson('./src/manifest.json'),
|
||||||
|
|
||||||
/** @todo Finish implementing prerendering similar to that of Preact CLI. */
|
/** @todo Finish implementing prerendering similar to that of Preact CLI. */
|
||||||
prerender() {
|
prerender() {
|
||||||
|
|||||||
Reference in New Issue
Block a user