POC for better module import syntax
This commit is contained in:
@@ -87,7 +87,7 @@ module.exports = {
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
payload: path.resolve(__dirname, '../src'),
|
||||
payload: path.resolve(__dirname, '../'),
|
||||
local: path.resolve(__dirname, '../demo')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
|
||||
import App from 'payload/client/components/App';
|
||||
import { Test, Test2 } from 'payload';
|
||||
|
||||
import Routes from './Routes';
|
||||
import store from './store';
|
||||
// import App from 'payload/client/components/App';
|
||||
|
||||
// import Routes from './Routes';
|
||||
// import store from './store';
|
||||
|
||||
console.log(Test);
|
||||
|
||||
const Index = () => {
|
||||
return (
|
||||
<App store={store}>
|
||||
<Routes />
|
||||
</App>
|
||||
<React.Fragment>
|
||||
<Test />
|
||||
<Test2 />
|
||||
</React.Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
42
index.js
42
index.js
@@ -1,41 +1 @@
|
||||
const path = require('path');
|
||||
const Collection = require('./Collection');
|
||||
|
||||
class Payload {
|
||||
constructor(options) {
|
||||
this.express = options.express;
|
||||
this.mongoose = options.mongoose;
|
||||
this.baseURL = options.baseURL;
|
||||
|
||||
this.views = path.join(__dirname, 'views');
|
||||
|
||||
this.collections = {};
|
||||
|
||||
this.express.get('/payload/admin', (req, res) => {
|
||||
res.render('admin',
|
||||
{
|
||||
title: 'Payload Admin'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
newCollection(key) {
|
||||
if (key in this.collections) {
|
||||
// TODO: Have discussion about how errors should be handled
|
||||
return new Error(`${key} already exists in collections`);
|
||||
}
|
||||
|
||||
return new Collection(this, key);
|
||||
}
|
||||
|
||||
getCollection(key) {
|
||||
if (!(key in this.collections)) {
|
||||
// TODO: Have discussion about how errors should be handled
|
||||
return new Error(`${key} does not exist or has not been registered yet`);
|
||||
}
|
||||
|
||||
return this.collections[key];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Payload;
|
||||
export * from './src/client/Components';
|
||||
|
||||
9
src/client/components/Test.js
Normal file
9
src/client/components/Test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
|
||||
const Test = () => {
|
||||
return (
|
||||
<h1>Test</h1>
|
||||
);
|
||||
};
|
||||
|
||||
export default Test;
|
||||
7
src/client/components/Test2.js
Normal file
7
src/client/components/Test2.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
export default () => {
|
||||
return (
|
||||
<h1>Test2</h1>
|
||||
);
|
||||
};
|
||||
7
src/client/components/index.js
Normal file
7
src/client/components/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import Test from './Test';
|
||||
import Test2 from './Test2';
|
||||
|
||||
export {
|
||||
Test,
|
||||
Test2
|
||||
};
|
||||
Reference in New Issue
Block a user