"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvePlugins = void 0;
const plugin_alias_1 = __importDefault(require("@rollup/plugin-alias"));
const plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
const resolve_1 = require("./resolve");
const esbuild_1 = require("./esbuild");
const importsAnalysis_1 = require("./importsAnalysis");
const css_1 = require("./css");
const asset_1 = require("./asset");
const clientInjections_1 = require("./clientInjections");
const html_1 = require("./html");
const wasm_1 = require("./wasm");
const worker_1 = require("./worker");
async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
    const isBuild = config.command === 'build';
    const buildPlugins = isBuild
        ? (await Promise.resolve().then(() => __importStar(require('../build')))).resolveBuildPlugins(config)
        : { pre: [], post: [] };
    return [
        plugin_alias_1.default({ entries: config.alias }),
        ...prePlugins,
        resolve_1.resolvePlugin({
            root: config.root,
            dedupe: config.dedupe,
            isBuild,
            asSrc: true
        }),
        html_1.htmlPlugin(),
        css_1.cssPlugin(config),
        config.esbuild !== false ? esbuild_1.esbuildPlugin(config.esbuild) : null,
        plugin_json_1.default({
            preferConst: true,
            namedExports: true
        }),
        wasm_1.wasmPlugin(config),
        worker_1.webWorkerPlugin(config),
        asset_1.assetPlugin(config),
        ...normalPlugins,
        css_1.cssPostPlugin(config),
        ...buildPlugins.pre,
        ...postPlugins,
        ...buildPlugins.post,
        // internal server-only plugins are always applied after everything else
        ...(isBuild
            ? []
            : [clientInjections_1.clientInjectionsPlugin(config), importsAnalysis_1.importAnalysisPlugin(config)])
    ].filter(Boolean);
}
exports.resolvePlugins = resolvePlugins;
//# sourceMappingURL=index.js.map