Use ES modules and dynamic import for Webpack latest builds (#16849)
This commit is contained in:
parent
197638b282
commit
fa1a6affa7
|
@ -10,6 +10,12 @@ supports es6-module-dynamic-import
|
||||||
not Safari < 13
|
not Safari < 13
|
||||||
not iOS < 13
|
not iOS < 13
|
||||||
|
|
||||||
|
# Exclude KaiOS, QQ, and UC browsers due to lack of sufficient feature support data
|
||||||
|
# Babel ignores these automatically, but we need here for Webpack to output ESM with dynamic imports
|
||||||
|
not KaiOS > 0
|
||||||
|
not QQAndroid > 0
|
||||||
|
not UCAndroid > 0
|
||||||
|
|
||||||
# Exclude unsupported browsers
|
# Exclude unsupported browsers
|
||||||
not dead
|
not dead
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ module.exports.htmlMinifierOptions = {
|
||||||
module.exports.terserOptions = ({ latestBuild, isTestBuild }) => ({
|
module.exports.terserOptions = ({ latestBuild, isTestBuild }) => ({
|
||||||
safari10: !latestBuild,
|
safari10: !latestBuild,
|
||||||
ecma: latestBuild ? 2015 : 5,
|
ecma: latestBuild ? 2015 : 5,
|
||||||
|
module: latestBuild,
|
||||||
format: { comments: false },
|
format: { comments: false },
|
||||||
sourceMap: !isTestBuild,
|
sourceMap: !isTestBuild,
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,7 +41,7 @@ const createWebpackConfig = ({
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
mode: isProdBuild ? "production" : "development",
|
mode: isProdBuild ? "production" : "development",
|
||||||
target: ["web", latestBuild ? "es2017" : "es5"],
|
target: `browserslist:${latestBuild ? "modern" : "legacy"}`,
|
||||||
// For tests/CI, source maps are skipped to gain build speed
|
// For tests/CI, source maps are skipped to gain build speed
|
||||||
// For production, generate source maps for accurate stack traces without source code
|
// For production, generate source maps for accurate stack traces without source code
|
||||||
// For development, generate "cheap" versions that can map to original line numbers
|
// For development, generate "cheap" versions that can map to original line numbers
|
||||||
|
@ -84,6 +84,13 @@ const createWebpackConfig = ({
|
||||||
],
|
],
|
||||||
moduleIds: isProdBuild && !isStatsBuild ? "deterministic" : "named",
|
moduleIds: isProdBuild && !isStatsBuild ? "deterministic" : "named",
|
||||||
chunkIds: isProdBuild && !isStatsBuild ? "deterministic" : "named",
|
chunkIds: isProdBuild && !isStatsBuild ? "deterministic" : "named",
|
||||||
|
splitChunks: {
|
||||||
|
// Disable splitting for web workers with ESM output
|
||||||
|
// Imports of external chunks are broken
|
||||||
|
chunks: latestBuild
|
||||||
|
? (chunk) => !chunk.canBeInitial() && !/^.+-worker$/.test(chunk.name)
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
!isStatsBuild && new WebpackBar({ fancy: !isProdBuild }),
|
!isStatsBuild && new WebpackBar({ fancy: !isProdBuild }),
|
||||||
|
@ -163,6 +170,7 @@ const createWebpackConfig = ({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
|
module: latestBuild,
|
||||||
filename: ({ chunk }) =>
|
filename: ({ chunk }) =>
|
||||||
!isProdBuild || isStatsBuild || dontHash.has(chunk.name)
|
!isProdBuild || isStatsBuild || dontHash.has(chunk.name)
|
||||||
? "[name].js"
|
? "[name].js"
|
||||||
|
@ -196,7 +204,7 @@ const createWebpackConfig = ({
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
experiments: {
|
experiments: {
|
||||||
topLevelAwait: true,
|
outputModule: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Remote, wrap } from "comlink";
|
import { Remote, wrap } from "comlink";
|
||||||
import type { Api } from "./sort_filter_worker";
|
import type { Api } from "./sort-filter-worker";
|
||||||
|
|
||||||
type FilterDataType = Api["filterData"];
|
type FilterDataType = Api["filterData"];
|
||||||
type FilterDataParamTypes = Parameters<FilterDataType>;
|
type FilterDataParamTypes = Parameters<FilterDataType>;
|
||||||
|
@ -9,27 +9,28 @@ type SortDataParamTypes = Parameters<SortDataType>;
|
||||||
|
|
||||||
let worker: Remote<Api> | undefined;
|
let worker: Remote<Api> | undefined;
|
||||||
|
|
||||||
|
const getWorker = () => {
|
||||||
|
if (!worker) {
|
||||||
|
worker = wrap(
|
||||||
|
new Worker(
|
||||||
|
/* webpackChunkName: "sort-filter-worker" */
|
||||||
|
new URL("./sort-filter-worker", import.meta.url)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return worker;
|
||||||
|
};
|
||||||
|
|
||||||
export const filterData = (
|
export const filterData = (
|
||||||
data: FilterDataParamTypes[0],
|
data: FilterDataParamTypes[0],
|
||||||
columns: FilterDataParamTypes[1],
|
columns: FilterDataParamTypes[1],
|
||||||
filter: FilterDataParamTypes[2]
|
filter: FilterDataParamTypes[2]
|
||||||
): Promise<ReturnType<FilterDataType>> => {
|
): Promise<ReturnType<FilterDataType>> =>
|
||||||
if (!worker) {
|
getWorker().filterData(data, columns, filter);
|
||||||
worker = wrap(new Worker(new URL("./sort_filter_worker", import.meta.url)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return worker.filterData(data, columns, filter);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const sortData = (
|
export const sortData = (
|
||||||
data: SortDataParamTypes[0],
|
data: SortDataParamTypes[0],
|
||||||
columns: SortDataParamTypes[1],
|
columns: SortDataParamTypes[1],
|
||||||
direction: SortDataParamTypes[2],
|
direction: SortDataParamTypes[2],
|
||||||
sortColumn: SortDataParamTypes[3]
|
sortColumn: SortDataParamTypes[3]
|
||||||
): Promise<ReturnType<SortDataType>> => {
|
): Promise<ReturnType<SortDataType>> =>
|
||||||
if (!worker) {
|
getWorker().sortData(data, columns, direction, sortColumn);
|
||||||
worker = wrap(new Worker(new URL("./sort_filter_worker", import.meta.url)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return worker.sortData(data, columns, direction, sortColumn);
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Remote, wrap } from "comlink";
|
import { Remote, wrap } from "comlink";
|
||||||
import type { Api } from "./markdown_worker";
|
import type { Api } from "./markdown-worker";
|
||||||
|
|
||||||
type RenderMarkdownType = Api["renderMarkdown"];
|
type RenderMarkdownType = Api["renderMarkdown"];
|
||||||
type RenderMarkdownParamTypes = Parameters<RenderMarkdownType>;
|
type RenderMarkdownParamTypes = Parameters<RenderMarkdownType>;
|
||||||
|
@ -12,8 +12,12 @@ export const renderMarkdown = async (
|
||||||
hassOptions?: RenderMarkdownParamTypes[2]
|
hassOptions?: RenderMarkdownParamTypes[2]
|
||||||
): Promise<ReturnType<RenderMarkdownType>> => {
|
): Promise<ReturnType<RenderMarkdownType>> => {
|
||||||
if (!worker) {
|
if (!worker) {
|
||||||
worker = wrap(new Worker(new URL("./markdown_worker", import.meta.url)));
|
worker = wrap(
|
||||||
|
new Worker(
|
||||||
|
/* webpackChunkName: "markdown-worker" */
|
||||||
|
new URL("./markdown-worker", import.meta.url)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return worker.renderMarkdown(content, markedOptions, hassOptions);
|
return worker.renderMarkdown(content, markedOptions, hassOptions);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
import webpack from "../build-scripts/webpack.cjs";
|
import webpack from "../build-scripts/webpack.cjs";
|
||||||
|
|
||||||
export default webpack.createAppConfig({
|
const config = webpack.createAppConfig({
|
||||||
isProdBuild: false,
|
isProdBuild: false,
|
||||||
latestBuild: true,
|
latestBuild: true,
|
||||||
isStatsBuild: false,
|
isStatsBuild: false,
|
||||||
isTestBuild: true,
|
isTestBuild: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// instant-mocha forces a CJS library, so cannot output ESM
|
||||||
|
config.output.module = false;
|
||||||
|
|
||||||
|
export default config;
|
||||||
|
|
Loading…
Reference in New Issue