'isActive', 'WebpackCSS' => 'loadCSS', 'WebpackJS' => 'loadJS', ]; } /** * Load CSS file * @param $path */ public static function loadCSS($path) { Requirements::css(self::_getPath($path)); } /** * Load JS file * @param $path */ public static function loadJS($path) { Requirements::javascript(self::_getPath($path)); } /** * Checks if dev mode is enabled and if webpack server is online * @return bool */ public static function isActive() { $class = __CLASS__; return Director::isDev() && !!@fsockopen( $class::config()->get('HOSTNAME'), $class::config()->get('PORT') ); } protected static function _getPath($path) { return self::isActive() && strpos($path,'//') === false ? self::_toDevServerPath($path) : self::_toPublicPath($path); } protected static function _toDevServerPath($path) { $class = __CLASS__; return sprintf( '%s%s:%s/%s', Director::protocol(), $class::config()->get('HOSTNAME'), $class::config()->get('PORT'), basename($path) ); } protected static function _toPublicPath($path) { $class = __CLASS__; return strpos($path,'//') === false ? Controller::join_links( $class::config()->get('DIST'), (strpos($path,'.css') ? 'css' : 'js' ), $path ) : $path; } }