mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Exclude packages rollup (#6007)
This commit is contained in:
parent
ad386c0e22
commit
872e46a076
51
build-scripts/rollup-plugins/ignore-plugin.js
Normal file
51
build-scripts/rollup-plugins/ignore-plugin.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
module.exports = function (userOptions = {}) {
|
||||||
|
// Files need to be absolute paths.
|
||||||
|
// This only works if the file has no exports
|
||||||
|
// and only is imported for its side effects
|
||||||
|
const files = userOptions.files || [];
|
||||||
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
return {
|
||||||
|
name: "ignore",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: "ignore",
|
||||||
|
resolveId(importee, importer) {
|
||||||
|
// Only use ignore to intercept imports that we don't control
|
||||||
|
// inside node_module dependencies.
|
||||||
|
if (
|
||||||
|
importee.endsWith("commonjsHelpers.js") ||
|
||||||
|
importee.endsWith("?commonjs-proxy") ||
|
||||||
|
!importer ||
|
||||||
|
!importer.includes("/node_modules/")
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let fullPath;
|
||||||
|
try {
|
||||||
|
fullPath = importee.startsWith(".")
|
||||||
|
? path.resolve(importee, importer)
|
||||||
|
: require.resolve(importee);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error in ignore plugin", { importee, importer }, err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return files.some((toIgnorePath) => fullPath.startsWith(toIgnorePath))
|
||||||
|
? fullPath
|
||||||
|
: null;
|
||||||
|
},
|
||||||
|
|
||||||
|
load(id) {
|
||||||
|
return files.some((toIgnorePath) => id.startsWith(toIgnorePath))
|
||||||
|
? {
|
||||||
|
code: "",
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
@ -11,8 +11,10 @@ const { terser } = require("rollup-plugin-terser");
|
|||||||
const manifest = require("./rollup-plugins/manifest-plugin");
|
const manifest = require("./rollup-plugins/manifest-plugin");
|
||||||
const worker = require("./rollup-plugins/worker-plugin");
|
const worker = require("./rollup-plugins/worker-plugin");
|
||||||
const dontHashPlugin = require("./rollup-plugins/dont-hash-plugin");
|
const dontHashPlugin = require("./rollup-plugins/dont-hash-plugin");
|
||||||
|
const ignore = require("./rollup-plugins/ignore-plugin");
|
||||||
|
|
||||||
const bundle = require("./bundle");
|
const bundle = require("./bundle");
|
||||||
|
const paths = require("./paths");
|
||||||
|
|
||||||
const extensions = [".js", ".ts"];
|
const extensions = [".js", ".ts"];
|
||||||
|
|
||||||
@ -39,11 +41,18 @@ const createRollupConfig = ({
|
|||||||
// Some entry points contain no JavaScript. This setting silences a warning about that.
|
// Some entry points contain no JavaScript. This setting silences a warning about that.
|
||||||
// https://rollupjs.org/guide/en/#preserveentrysignatures
|
// https://rollupjs.org/guide/en/#preserveentrysignatures
|
||||||
preserveEntrySignatures: false,
|
preserveEntrySignatures: false,
|
||||||
external:
|
|
||||||
bundle.ignorePackages({ latestBuild }) +
|
|
||||||
bundle.emptyPackages({ latestBuild }),
|
|
||||||
plugins: [
|
plugins: [
|
||||||
resolve({ extensions, preferBuiltins: false, browser: true }),
|
ignore({
|
||||||
|
files: bundle
|
||||||
|
.ignorePackages({ latestBuild })
|
||||||
|
.concat(bundle.emptyPackages({ latestBuild })),
|
||||||
|
}),
|
||||||
|
resolve({
|
||||||
|
extensions,
|
||||||
|
preferBuiltins: false,
|
||||||
|
browser: true,
|
||||||
|
rootDir: paths.polymer_dir,
|
||||||
|
}),
|
||||||
commonjs({
|
commonjs({
|
||||||
namedExports: {
|
namedExports: {
|
||||||
"js-yaml": ["safeDump", "safeLoad"],
|
"js-yaml": ["safeDump", "safeLoad"],
|
||||||
@ -57,7 +66,7 @@ const createRollupConfig = ({
|
|||||||
}),
|
}),
|
||||||
string({
|
string({
|
||||||
// Import certain extensions as strings
|
// Import certain extensions as strings
|
||||||
include: ["**/*.css"],
|
include: [path.join(paths.polymer_dir, "node_modules/**/*.css")],
|
||||||
}),
|
}),
|
||||||
replace(
|
replace(
|
||||||
bundle.definedVars({ isProdBuild, latestBuild, defineOverlay })
|
bundle.definedVars({ isProdBuild, latestBuild, defineOverlay })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user