mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
build: improve webpack config (#3463)
This commit is contained in:
@@ -8,9 +8,9 @@ export const productionCacheGroups = {
|
|||||||
test: /[\\/]node_modules[\\/]/,
|
test: /[\\/]node_modules[\\/]/,
|
||||||
name(module: any) {
|
name(module: any) {
|
||||||
// https://hackernoon.com/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758
|
// https://hackernoon.com/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758
|
||||||
const name =
|
const name = module.context.match(
|
||||||
module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)?.[1] ??
|
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
|
||||||
'unknown';
|
)?.[1];
|
||||||
return `npm-async-${name}`;
|
return `npm-async-${name}`;
|
||||||
},
|
},
|
||||||
priority: Number.MAX_SAFE_INTEGER,
|
priority: Number.MAX_SAFE_INTEGER,
|
||||||
|
|||||||
@@ -256,9 +256,9 @@ export const createConfiguration: (
|
|||||||
new HTMLPlugin({
|
new HTMLPlugin({
|
||||||
template: join(rootPath, '.webpack', 'template.html'),
|
template: join(rootPath, '.webpack', 'template.html'),
|
||||||
inject: 'body',
|
inject: 'body',
|
||||||
scriptLoading: 'defer',
|
scriptLoading: 'module',
|
||||||
minify: false,
|
minify: false,
|
||||||
chunks: ['index', 'plugin'],
|
chunks: ['index', 'plugin', 'polyfill-ses'],
|
||||||
filename: 'index.html',
|
filename: 'index.html',
|
||||||
}),
|
}),
|
||||||
new VanillaExtractPlugin(),
|
new VanillaExtractPlugin(),
|
||||||
|
|||||||
@@ -14,15 +14,20 @@ export default async function (cli_env: any, _: any) {
|
|||||||
const config = createConfiguration(flags, runtimeConfig);
|
const config = createConfiguration(flags, runtimeConfig);
|
||||||
return merge(config, {
|
return merge(config, {
|
||||||
entry: {
|
entry: {
|
||||||
index: {
|
'polyfill-ses': {
|
||||||
asyncChunks: false,
|
asyncChunks: false,
|
||||||
import: resolve(rootPath, 'src/index.tsx'),
|
import: resolve(rootPath, 'src/polyfill/ses.ts'),
|
||||||
},
|
},
|
||||||
plugin: {
|
plugin: {
|
||||||
dependOn: ['index'],
|
|
||||||
asyncChunks: true,
|
asyncChunks: true,
|
||||||
|
dependOn: ['polyfill-ses'],
|
||||||
import: resolve(rootPath, 'src/bootstrap/register-plugins.ts'),
|
import: resolve(rootPath, 'src/bootstrap/register-plugins.ts'),
|
||||||
},
|
},
|
||||||
|
index: {
|
||||||
|
asyncChunks: false,
|
||||||
|
dependOn: ['polyfill-ses', 'plugin'],
|
||||||
|
import: resolve(rootPath, 'src/index.tsx'),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"jsxImportSource": "@emotion/react",
|
"jsxImportSource": "@emotion/react",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"types": ["webpack-env"]
|
"types": ["webpack-env", "ses"]
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
||||||
"exclude": ["node_modules"],
|
"exclude": ["node_modules"],
|
||||||
|
|||||||
Reference in New Issue
Block a user