Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

build: improve webpack config (#3463)

Alex Yangcc7de52cafdc
diff --git a/apps/core/.webpack/cache-group.ts b/apps/core/.webpack/cache-group.ts
index 0f8b2c2cb0..89f7a4b127 100644
--- a/apps/core/.webpack/cache-group.ts
+++ b/apps/core/.webpack/cache-group.ts
@@ -8,9 +8,9 @@ export const productionCacheGroups = {
test: /[\\/]node_modules[\\/]/,
name(module: any) {
// https://hackernoon.com/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758
- const name =
- module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)?.[1] ??
- 'unknown';
+ const name = module.context.match(
+ /[\\/]node_modules[\\/](.*?)([\\/]|$)/
+ )?.[1];
return `npm-async-${name}`;
},
priority: Number.MAX_SAFE_INTEGER,
diff --git a/apps/core/.webpack/config.ts b/apps/core/.webpack/config.ts
index f2e57e8def..f285d669d4 100644
--- a/apps/core/.webpack/config.ts
+++ b/apps/core/.webpack/config.ts
@@ -256,9 +256,9 @@ export const createConfiguration: (
new HTMLPlugin({
template: join(rootPath, '.webpack', 'template.html'),
inject: 'body',
- scriptLoading: 'defer',
+ scriptLoading: 'module',
minify: false,
- chunks: ['index', 'plugin'],
+ chunks: ['index', 'plugin', 'polyfill-ses'],
filename: 'index.html',
}),
new VanillaExtractPlugin(),
diff --git a/apps/core/.webpack/webpack.config.ts b/apps/core/.webpack/webpack.config.ts
index 9c58cf63cc..ddf671e983 100644
--- a/apps/core/.webpack/webpack.config.ts
+++ b/apps/core/.webpack/webpack.config.ts
@@ -14,15 +14,20 @@ export default async function (cli_env: any, _: any) {
const config = createConfiguration(flags, runtimeConfig);
return merge(config, {
entry: {
- index: {
+ 'polyfill-ses': {
asyncChunks: false,
- import: resolve(rootPath, 'src/index.tsx'),
+ import: resolve(rootPath, 'src/polyfill/ses.ts'),
},
plugin: {
- dependOn: ['index'],
asyncChunks: true,
+ dependOn: ['polyfill-ses'],
import: resolve(rootPath, 'src/bootstrap/register-plugins.ts'),
},
+ index: {
+ asyncChunks: false,
+ dependOn: ['polyfill-ses', 'plugin'],
+ import: resolve(rootPath, 'src/index.tsx'),
+ },
},
});
}
diff --git a/apps/core/src/polyfill/ses.ts b/apps/core/src/polyfill/ses.ts
new file mode 100644
index 0000000000..03b75cfed0
--- /dev/null
+++ b/apps/core/src/polyfill/ses.ts
@@ -0,0 +1,19 @@
+import 'ses';
+
+if (!process.env.COVERAGE) {
+ lockdown({
+ evalTaming: 'unsafeEval',
+ overrideTaming: 'severe',
+ consoleTaming: 'unsafe',
+ errorTaming: 'unsafe',
+ errorTrapping: 'platform',
+ unhandledRejectionTrapping: 'report',
+ });
+
+ console.log('SES lockdown complete');
+} else {
+ Object.defineProperty(globalThis, 'harden', {
+ value: (x: any) => Object.freeze(x),
+ writable: false,
+ });
+}
diff --git a/apps/core/tsconfig.json b/apps/core/tsconfig.json
index b0fa6678fa..2bfd84ba8e 100644
--- a/apps/core/tsconfig.json
+++ b/apps/core/tsconfig.json
@@ -16,7 +16,7 @@
"jsxImportSource": "@emotion/react",
"incremental": true,
"experimentalDecorators": true,
- "types": ["webpack-env"]
+ "types": ["webpack-env", "ses"]
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules"],