build: improve webpack config (#3561)

This commit is contained in:
Alex Yang
2023-08-03 16:05:46 -07:00
committed by GitHub
parent f2ac4c7eda
commit 0c16eb1189
21 changed files with 365 additions and 234 deletions
+22
View File
@@ -79,6 +79,10 @@ export const createConfiguration: (
name: 'affine',
// to set a correct base path for the source map
context: projectRoot,
experiments: {
topLevelAwait: true,
outputModule: false,
},
output: {
environment: {
module: true,
@@ -130,6 +134,10 @@ export const createConfiguration: (
module: {
parser: {
javascript: {
// Do not mock Node.js globals
node: false,
requireJs: false,
import: true,
// Treat as missing export as error
strictExportPresence: true,
},
@@ -137,6 +145,20 @@ export const createConfiguration: (
rules: [
{
test: /\.m?js?$/,
enforce: 'pre',
use: [
{
loader: require.resolve('source-map-loader'),
options: {
filterSourceMappingUrl: (
_url: string,
resourcePath: string
) => {
return resourcePath.includes('@blocksuite');
},
},
},
],
resolve: {
fullySpecified: false,
},
+9 -11
View File
@@ -15,23 +15,21 @@ export default async function (cli_env: any, _: any) {
const config = createConfiguration(flags, runtimeConfig);
return merge(config, {
entry: {
'polyfill-ses': {
asyncChunks: false,
'polyfill/ses': {
import: resolve(rootPath, 'src/polyfill/ses.ts'),
},
plugin: {
asyncChunks: true,
dependOn: ['polyfill-ses'],
dependOn: ['polyfill/ses'],
import: resolve(rootPath, 'src/bootstrap/register-plugins.ts'),
},
index: {
asyncChunks: false,
dependOn: ['polyfill-ses', 'plugin'],
app: {
chunkLoading: 'import',
dependOn: ['polyfill/ses', 'plugin'],
import: resolve(rootPath, 'src/index.tsx'),
},
'_plugin/index.test': {
asyncChunks: false,
dependOn: ['polyfill-ses', 'plugin'],
chunkLoading: 'import',
dependOn: ['polyfill/ses', 'plugin'],
import: resolve(rootPath, 'src/_plugin/index.test.tsx'),
},
},
@@ -41,7 +39,7 @@ export default async function (cli_env: any, _: any) {
inject: 'body',
scriptLoading: 'module',
minify: false,
chunks: ['index', 'plugin', 'polyfill-ses'],
chunks: ['app', 'plugin', 'polyfill/ses'],
filename: 'index.html',
}),
new HTMLPlugin({
@@ -49,7 +47,7 @@ export default async function (cli_env: any, _: any) {
inject: 'body',
scriptLoading: 'module',
minify: false,
chunks: ['_plugin/index.test', 'plugin', 'polyfill-ses'],
chunks: ['_plugin/index.test', 'plugin', 'polyfill/ses'],
filename: '_plugin/index.html',
}),
],