replaces moment with date-fns

This commit is contained in:
James
2020-06-12 15:57:29 -04:00
parent aa13bd9084
commit 4e63863338
8 changed files with 170 additions and 38 deletions

17
src/bin/build.js Normal file → Executable file
View File

@@ -1,16 +1,24 @@
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
const path = require('path');
const webpack = require('webpack');
const getWebpackProdConfig = require('../webpack/getWebpackProdConfig');
const findConfig = require('../utilities/findConfig');
module.exports = (args) => {
const configPath = path.resolve(process.cwd(), (args.config || './payload.config.js'));
module.exports = () => {
const configPath = findConfig();
try {
const config = require(configPath);
const webpackProdConfig = getWebpackProdConfig(config);
const webpackProdConfig = getWebpackProdConfig({
...config,
paths: {
...(config.paths || {}),
config: configPath,
},
});
webpack(webpackProdConfig, (err, stats) => { // Stats Object
if (err || stats.hasErrors()) {
// Handle errors here
@@ -24,6 +32,7 @@ module.exports = (args) => {
// Done processing
});
} catch (err) {
console.log(err);
console.error(`Error: can't find the configuration file located at ${configPath}.`);
}

View File

@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link, useRouteMatch, useLocation } from 'react-router-dom';
import moment from 'moment';
import { format } from 'date-fns';
import config from 'payload/config';
import Eyebrow from '../../../elements/Eyebrow';
import Form from '../../../forms/Form';
@@ -127,11 +127,11 @@ const DefaultEditView = (props) => {
<>
<li>
<div className={`${baseClass}__label`}>Last Modified</div>
<div>{moment(data.updatedAt).format('MMMM Do YYYY, h:mma')}</div>
<div>{format(data.updatedAt, 'MMMM do yyyy, h:mma')}</div>
</li>
<li>
<div className={`${baseClass}__label`}>Created</div>
<div>{moment(data.createdAt).format('MMMM Do YYYY, h:mma')}</div>
<div>{format(data.createdAt, 'MMMM do yyyy, h:mma')}</div>
</li>
</>
)}

View File

@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import moment from 'moment';
import { format } from 'date-fns';
import config from 'payload/config';
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
@@ -34,7 +34,7 @@ const DefaultCell = (props) => {
<WrapElement {...wrapElementProps}>
{(field.type === 'date' && cellData) && (
<span>
{moment(cellData).format('MMMM Do YYYY, h:mma')}
{format(new Date(cellData), 'MMMM do yyyy, h:mma')}
</span>
)}
{field.type !== 'date' && (

View File

@@ -0,0 +1,20 @@
const path = require('path');
const fs = require('fs');
const findConfig = () => {
let configPath = path.resolve(__dirname, '../../../payload.config.js');
if (!fs.existsSync(configPath)) {
if (typeof process.env.PAYLOAD_CONFIG_PATH !== 'string') {
throw new Error('Error: cannot find Payload config. Please create a configuration file located at the root of your project called "payload.config.js".');
}
if (fs.existsSync(process.env.PAYLOAD_CONFIG_PATH)) {
configPath = process.env.PAYLOAD_CONFIG_PATH;
}
}
return configPath;
};
module.exports = findConfig;

View File

@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const findConfig = require('./findConfig');
/* eslint-disable import/no-dynamic-require */
/* eslint-disable global-require */
@@ -13,18 +14,7 @@ const getConfig = (options = {}) => {
throw new Error('Error: missing MongoDB connection URL.');
}
let configPath = path.resolve(__dirname, '../../../payload.config.js');
if (!fs.existsSync(configPath)) {
if (typeof options.config !== 'string') {
throw new Error('Error: cannot find Payload config. Please create a configuration file located at the root of your project called "payload.config.js".');
}
if (fs.existsSync(options.config)) {
configPath = options.config;
}
}
const configPath = findConfig();
const publicConfig = require(configPath);
return {
@@ -33,7 +23,7 @@ const getConfig = (options = {}) => {
mongoURL: options.mongoURL,
email: options.email,
paths: {
...publicConfig.paths,
...(publicConfig.paths || {}),
config: configPath,
},
};

View File

@@ -1,20 +1,30 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const path = require('path');
const getStyleLoaders = require('./getStyleLoaders');
module.exports = (config) => {
return {
const webpackConfig = {
entry: {
main: [path.resolve(__dirname, '../components/index.js')],
main: [path.resolve(__dirname, '../client/components/index.js')],
},
output: {
path: path.resolve(process.cwd(), 'build'),
filename: '[name].[chunkhash].js',
},
mode: 'production',
resolveLoader: { modules: [path.join(__dirname, '../../../node_modules')] },
resolveLoader: { modules: [path.join(__dirname, '../../node_modules')] },
module: {
rules: [
{
test: require.resolve('../client/components/customComponents'),
use: [
{
loader: 'val-loader',
options: config,
},
],
},
{
test: /\.js$/,
exclude: /node_modules/,
@@ -26,13 +36,14 @@ module.exports = (config) => {
require.resolve('@babel/preset-env'),
{
modules: 'commonjs',
targets: '> 1%, not dead',
},
],
require.resolve('@babel/preset-react'),
],
plugins: [
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('babel-plugin-add-module-exports'),
[
require.resolve('@babel/plugin-transform-runtime'),
{
@@ -87,17 +98,29 @@ module.exports = (config) => {
],
},
plugins: [
new BundleAnalyzerPlugin({
generateStatsFile: true,
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../index.html'),
template: path.resolve(__dirname, '../client/index.html'),
filename: './index.html',
minify: true,
}),
],
resolve: {
modules: ['node_modules', path.resolve(__dirname, '../../../node_modules')],
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
alias: {
'payload-scss-overrides': config.paths.scss,
'payload/unsanitizedConfig': config.paths.config,
'payload/config': path.resolve(__dirname, '../client/config.js'),
},
},
};
if (config.paths.scss) {
webpackConfig.resolve.alias['payload-scss-overrides'] = config.paths.scss;
} else {
webpackConfig.resolve.alias['payload-scss-overrides'] = path.resolve(__dirname, '../client/scss/overrides.scss');
}
return webpackConfig;
};