Exemplo n.º 1
0
        public override void Process(GetPageRenderingArgs args)
        {
            // Safety check - if the config is set to webpack, don't run this pipeline or it will fail.
            if (ReactSettingsProvider.Current.BundleType == Settings.BundleTypes.Webpack)
            {
                return;
            }

            AddRenderingAssets(args.PageContext.PageDefinition.Renderings);

            // Create the bundle for the render
            var bundle = new BabelBundle(ReactSettingsProvider.Current.BundleName);

            foreach (var jsxFile in JsxRepository.Current.Items)
            {
                bundle.Include(jsxFile);

                if (!ReactSiteConfiguration.Configuration.Scripts.Any(script => script.Equals(jsxFile)))
                {
                    ReactSiteConfiguration.Configuration.AddScript(jsxFile);
                }
            }

            BundleTable.Bundles.Add(bundle);
        }
        public override void Process(GetPageRenderingArgs args)
        {
            this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings);

            var bundleName = ReactSettingsProvider.Current.BundleName;

            if (string.IsNullOrWhiteSpace(bundleName))
            {
                bundleName = "~/bundles/react";
            }

            var bundle = new BabelBundle(bundleName);

            foreach (var jsxFile in JsxRepository.Current.Items)
            {
                bundle.Include(jsxFile);

                if (!ReactSiteConfiguration.Configuration.Scripts.Any(s => s.Equals(jsxFile)))
                {
                    ReactSiteConfiguration.Configuration.AddScript(jsxFile);
                }
            }

            BundleTable.Bundles.Add(bundle);
        }
Exemplo n.º 3
0
        public static void Configure()
        {
            // Initialize the JavaScript Engine for the application. Default to the V8 engine
            IJsEngineSwitcher engineSwitcher = JsEngineSwitcher.Current;

            engineSwitcher.EngineFactories.Clear();
            engineSwitcher.EngineFactories.AddV8(new V8Settings());

            engineSwitcher.DefaultEngineName = V8JsEngine.EngineName;

            ViewEngines.Engines.Add(new JsxViewEngine());
            ReactSiteConfiguration.Configuration.SetReuseJavaScriptEngines(true);

            if (ReactSettingsProvider.Current.UseCamelCasePropertyNames)
            {
                ReactSiteConfiguration.Configuration.JsonSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }

            if (ReactSettingsProvider.Current.BundleType == "webpack")
            {
                ReactSiteConfiguration.Configuration
                .SetUseDebugReact(ReactSettingsProvider.Current.UseDebugReactScript)
                .SetLoadBabel(false)
                .AddScriptWithoutTransform(ReactSettingsProvider.Current.ServerScript);
            }
            else
            {
                var searchPath = string.Format("{0}/Views/", HostingEnvironment.ApplicationPhysicalPath);
                var jsxViews   = Directory.GetFiles(searchPath, "*.jsx", SearchOption.AllDirectories)
                                 .Select(view => view.Replace(HostingEnvironment.ApplicationPhysicalPath, @"~/"));

                ReactSiteConfiguration.Configuration
                .SetUseDebugReact(ReactSettingsProvider.Current.UseDebugReactScript)
                .SetLoadBabel(true);

                if (!ReactSettingsProvider.Current.UseDebugReactScript)
                {
                    ReactSiteConfiguration.Configuration.BabelConfig.Presets = new HashSet <string> {
                        "react", "es2015"
                    };
                }

                // Create the bundle for the render
                var bundle = new BabelBundle(ReactSettingsProvider.Current.BundleName);
                foreach (var view in jsxViews)
                {
                    Sitecore.Diagnostics.Log.Info($"Sitecore.React: Adding view [{view}]", typeof(ReactConfig));
                    bundle.Include(view);
                    if (!ReactSiteConfiguration.Configuration.Scripts.Any(script => script.Equals(view)))
                    {
                        ReactSiteConfiguration.Configuration.AddScript(view);
                    }
                }

                BundleTable.Bundles.Add(bundle);
            }
        }
Exemplo n.º 4
0
        public override void Process(GetPageRenderingArgs args)
        {
            this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings);

            // Create the bundle for the render
            var bundle = new BabelBundle("~/bundles/react");

            foreach (var jsxFile in JsxRepository.Current.Items)
            {
                bundle.Include(jsxFile);

                if (!ReactSiteConfiguration.Configuration.Scripts.Any(s => s.Equals(jsxFile)))
                {
                    ReactSiteConfiguration.Configuration.AddScript(jsxFile);
                }
            }

            BundleTable.Bundles.Add(bundle);
        }