forked from KevinBatdorf/wp-xeet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
33 lines (30 loc) · 894 Bytes
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const fs = require('fs');
const path = require('path');
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const VirtualModulesPlugin = require('webpack-virtual-modules');
const directoryPath = path.resolve(__dirname, './src/front/vercel');
const tsxFiles = fs
.readdirSync(directoryPath)
.filter((file) => file.endsWith('.tsx'));
let importStatementsString = '';
tsxFiles.forEach((file) => {
importStatementsString += `import '../src/front/vercel/${file}';\n`;
});
module.exports = {
...defaultConfig,
entry: {
...defaultConfig.entry(),
xeet: './virtual/xeet.tsx',
},
plugins: [
...defaultConfig.plugins,
new VirtualModulesPlugin({
'virtual/xeet.tsx': `
import ReactDOM from 'react-dom';
import { Tweet } from 'react-tweet';
${importStatementsString}
ReactDOM.render(<Tweet />, document.getElementById('root'));
`,
}),
],
};