import { Stylable, StylableConfig } from '@stylable/core'; import { OptimizeConfig, DiagnosticsMode, IStylableOptimizer, validateDefaultConfig, } from '@stylable/core/dist/index-internal'; import { createNamespaceStrategyNode } from '@stylable/node'; import { sortModulesByDepth, loadStylableConfig, calcDepth } from '@stylable/build-tools'; import { StylableOptimizer } from '@stylable/optimizer'; import cloneDeep from 'lodash.clonedeep'; import type { Compilation, Compiler, Module, NormalModule, WebpackError } from 'webpack'; import { getStaticPublicPath, isStylableModule, isLoadedNativeCSSModule, isAssetModule, isLoadedWithKnownAssetLoader, injectLoader, findIfStylableModuleUsed, staticCSSWith, getStylableBuildMeta, reportNamespaceCollision, createOptimizationMapping, getTopLevelInputFilesystem, createDecacheRequire, createStylableResolverCacheMap, createCalcDepthContext, provideStylableModules, emitCSSFile, getEntryPointModules, getOnlyChunk, getStylableBuildData, isDependencyOf, normalizeNamespaceCollisionOption, getWebpackBuildMeta, } from './plugin-utils.js'; import { injectCssModules } from './mini-css-support.js'; import type { BuildData, EntryPoint, LoaderData, NormalModuleFactory, ResolveOptionsWebpackOptions, StylableBuildMeta, StylableLoaderContext, } from './types.js'; import { parse } from 'postcss'; import { getWebpackEntities, StylableWebpackEntities } from './webpack-entities.js'; import { resolveConfig as resolveStcConfig, STCBuilder } from '@stylable/cli'; import { createWebpackResolver } from './legacy-module-resolver.js'; type OptimizeOptions = OptimizeConfig & { minify?: boolean; }; export interface StylableWebpackPluginOptions { /** * Filename of the output bundle when emitting css bundle * supports * - [contenthash] replacer - "stylable.[contenthash].css" - based on file content hash * - [name] replacer - "[name].css" - based on entry name - is not supported in "extractMode: 'single'" with multiple entries */ filename?: string; /** * Determine the way css is injected to the document * js - every js module contains the css and inject it independently * css - emit bundled css asset to injected via link * mini-css - inject css modules via webpack mini-css-extract-plugin (can support dynamic splitting but order is not deterministic) * none - will not generate any output css (usually good for ssr bundles) */ cssInjection?: 'js' | 'css' | 'mini-css' | 'none'; /** * Determine the runtime stylesheet id kind used by the cssInjection js mode * This sets the value of the st_id attribute on the stylesheet element * default for dev - 'module' * default for prod - 'namespace' */ runtimeStylesheetId?: 'module' | 'namespace'; /** * Config how error and warning reported to webpack by stylable * auto - Stylable warning will emit Webpack warning and Stylable error will emit Webpack error * strict - Stylable error and warning will emit Webpack error * loose - Stylable error and warning will emit Webpack warning */ diagnosticsMode?: DiagnosticsMode; /** * Target of the js module * oldie - ES3 compatible * modern - ES2105 compatible */ target?: 'oldie' | 'modern'; /** * Set the