Skip to content

Commit cc0e719

Browse files
committed
refactor: use pack-up for bundling
1 parent 203fb4e commit cc0e719

26 files changed

Lines changed: 731 additions & 123 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ files
99
.DS_Store
1010
npm-debug.log
1111
.idea
12+
13+
# Production build
14+
build
15+
dist
16+
bundle

admin/src/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ export default {
4949
bootstrap(app) {},
5050
async registerTrads({ locales }) {
5151
const importedTrads = await Promise.all(
52-
locales.map(async (locale) => {
53-
try {
54-
// eslint-disable-next-line import/no-dynamic-require, global-require
55-
const data = require(`./translations/${locale}.json`);
56-
return {
57-
data: prefixPluginTranslations(data, pluginId),
58-
locale,
59-
};
60-
} catch {
61-
return {
62-
data: {},
63-
locale,
64-
};
65-
}
66-
}),
52+
locales.map((locale) => {
53+
return import(`./translations/${locale}.json`)
54+
.then(({ default: data }) => {
55+
return {
56+
data: prefixPluginTranslations(data, pluginId),
57+
locale,
58+
};
59+
})
60+
.catch(() => {
61+
return {
62+
data: {},
63+
locale,
64+
};
65+
});
66+
})
6767
);
6868

6969
return Promise.resolve(importedTrads);

bin/config-sync

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
'use strict';
44

5-
require('../server/cli');
5+
require('../dist/cli');

package.json

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@
1313
"bin": {
1414
"config-sync": "./bin/config-sync"
1515
},
16+
"exports": {
17+
"./strapi-admin": {
18+
"source": "./admin/src/index.js",
19+
"import": "./dist/admin/index.mjs",
20+
"require": "./dist/admin/index.js",
21+
"default": "./dist/admin/index.js"
22+
},
23+
"./strapi-server": {
24+
"source": "./server/index.js",
25+
"import": "./dist/server/index.mjs",
26+
"require": "./dist/server/index.js",
27+
"default": "./dist/server/index.js"
28+
},
29+
"./package.json": "./package.json"
30+
},
1631
"scripts": {
17-
"develop": "nodemon -e js,jsx --ignore playground --exec \"yalc publish && yalc push\"",
18-
"build": "yalc push --publish",
32+
"develop": "strapi-plugin watch:link",
33+
"watch": "pack-up watch",
34+
"build": "pack-up build && yalc push --publish",
1935
"eslint": "eslint --max-warnings=0 './**/*.{js,jsx}'",
2036
"eslint:fix": "eslint --fix './**/*.{js,jsx}'",
2137
"test:unit": "jest --verbose",
@@ -52,18 +68,20 @@
5268
}
5369
],
5470
"files": [
55-
"admin",
56-
"server",
57-
"bin",
58-
"strapi-admin.js",
59-
"strapi-server.js"
71+
"dist",
72+
"bin"
6073
],
6174
"peerDependencies": {
62-
"@strapi/strapi": "^5.0.0"
75+
"@strapi/strapi": "^5.0.0",
76+
"react": "^17.0.0 || ^18.0.0",
77+
"react-dom": "^17.0.0 || ^18.0.0",
78+
"react-router-dom": "^5.2.0",
79+
"styled-components": "^5.2.1"
6380
},
6481
"devDependencies": {
6582
"@strapi/design-system": "2.0.0-rc.11",
6683
"@strapi/icons": "2.0.0-rc.11",
84+
"@strapi/sdk-plugin": "^5.2.7",
6785
"@strapi/strapi": "5.0.4",
6886
"@strapi/utils": "5.0.4",
6987
"babel-eslint": "9.0.0",

packup.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { defineConfig } from '@strapi/pack-up';
3+
4+
export default defineConfig({
5+
bundles: [
6+
{
7+
source: './admin/src/index.js',
8+
import: './dist/admin/index.mjs',
9+
require: './dist/admin/index.js',
10+
runtime: 'web',
11+
},
12+
{
13+
source: './server/index.js',
14+
import: './dist/server/index.mjs',
15+
require: './dist/server/index.js',
16+
runtime: 'node',
17+
},
18+
{
19+
source: './server/cli.js',
20+
import: './dist/cli/index.mjs',
21+
require: './dist/cli/index.js',
22+
runtime: 'node',
23+
},
24+
],
25+
dist: './dist',
26+
exports: {},
27+
});

server/bootstrap.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
const fs = require('fs');
3+
import fs from 'fs';
44

5-
const ConfigType = require('./config/type');
6-
const defaultTypes = require('./config/types');
7-
const { logMessage } = require('./utils');
5+
import ConfigType from './config/type';
6+
import defaultTypes from './config/types';
7+
import { logMessage } from './utils';
88

99
/**
1010
* An asynchronous bootstrap function that runs before
@@ -16,7 +16,7 @@ const { logMessage } = require('./utils');
1616
* See more details here: https://strapi.io/documentation/v3.x/concepts/configurations.html#bootstrap
1717
*/
1818

19-
module.exports = async () => {
19+
export default async () => {
2020
// Register config types.
2121
const registerTypes = () => {
2222
const types = {};

server/cli.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const { Command } = require('commander');
5-
const Table = require('cli-table');
6-
const chalk = require('chalk');
7-
const inquirer = require('inquirer');
8-
const { isEmpty } = require('lodash');
9-
const { createStrapi, compileStrapi } = require('@strapi/strapi');
10-
const gitDiff = require('git-diff');
11-
12-
const warnings = require('./warnings');
13-
const packageJSON = require('../package.json');
3+
import fs from 'fs';
4+
import { Command } from 'commander';
5+
import Table from 'cli-table';
6+
import chalk from 'chalk';
7+
import inquirer from 'inquirer';
8+
import { isEmpty } from 'lodash';
9+
import { createStrapi, compileStrapi } from '@strapi/strapi';
10+
import gitDiff from 'git-diff';
11+
12+
import warnings from './warnings';
13+
import packageJSON from '../package.json';
1414

1515
const program = new Command();
1616

server/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
module.exports = {
3+
export default {
44
default: {
55
syncDir: "config/sync/",
66
minify: false,

server/config/type.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { isEmpty } = require('lodash');
2-
const { logMessage, sanitizeConfig, dynamicSort, noLimit, getCombinedUid, getCombinedUidWhereFilter, getUidParamsFromName } = require('../utils');
3-
const { difference, same } = require('../utils/getArrayDiff');
4-
const queryFallBack = require('../utils/queryFallBack');
1+
import { isEmpty } from 'lodash';
2+
import { logMessage, sanitizeConfig, dynamicSort, noLimit, getCombinedUid, getCombinedUidWhereFilter, getUidParamsFromName } from '../utils';
3+
import { difference, same } from '../utils/getArrayDiff';
4+
import queryFallBack from '../utils/queryFallBack';
55

66
const ConfigType = class ConfigType {
77
constructor({ queryString, configName, uid, jsonFields, relations, components }) {
@@ -270,4 +270,4 @@ const ConfigType = class ConfigType {
270270
}
271271
};
272272

273-
module.exports = ConfigType;
273+
export default ConfigType;

server/config/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ const types = (strapi) => {
4949
return typesArray;
5050
};
5151

52-
module.exports = types;
52+
export default types;

0 commit comments

Comments
 (0)