use std::path::PathBuf;
use crate::configuration::DEFAULT_TSCONFIG_FILENAME;
use super::defaults::webpack_defaults::{WebpackDefaults, webpack_defaults_factory};
pub use super::get_webpack_config_path;
use super::plugins::plugins_loader::MultiNestCompilerPlugins;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct WebpackCompiler;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WebpackCompilerRunPlan {
pub default_options: WebpackDefaults,
pub user_config_path: Option<PathBuf>,
pub watch: bool,
pub mode: String,
pub stats_errors: usize,
pub stats_warnings: usize,
}
impl WebpackCompiler {
pub fn plan_run(
source_root: &str,
relative_source_root: &str,
entry_filename: &str,
is_debug_enabled: bool,
ts_config_file: Option<&str>,
plugins: &MultiNestCompilerPlugins,
user_config_path: Option<PathBuf>,
watch: bool,
) -> WebpackCompilerRunPlan {
let mut default_options = webpack_defaults_factory(
source_root,
relative_source_root,
entry_filename,
is_debug_enabled,
Some(ts_config_file.unwrap_or(DEFAULT_TSCONFIG_FILENAME)),
plugins,
);
if watch {
default_options.mode = "development".to_string();
}
WebpackCompilerRunPlan {
mode: default_options.mode.clone(),
default_options,
user_config_path,
watch,
stats_errors: 0,
stats_warnings: 0,
}
}
pub fn format_building_message() -> &'static str {
"Webpack is building your sources..."
}
pub fn should_fail(errors: usize) -> bool {
errors > 0
}
}