"use strict";

exports.__esModule = true;
exports.decorateNextJsWebpackConfig = void 0;
var _webpackPlugin = require("@stylable/webpack-plugin");
var _optimizer = require("@stylable/optimizer");
const stylableOptimizer = new _optimizer.StylableOptimizer();
const packages = ['@wix/design-system', '@wix/patterns', '@wix/wix-style-react-incubator'];
const decorateNextJsWebpackConfig = (config, {
  isServer
}) => {
  // causes provided packages to be bundled (not external)
  if (isServer && Array.isArray(config.externals)) {
    const nextExternals = config.externals[0];
    config.externals = [async ctx => {
      for (const pack of packages) {
        var _ctx$request;
        if ((_ctx$request = ctx.request) != null && _ctx$request.startsWith(pack)) {
          return false;
        }
      }
      return nextExternals(ctx);
    }];
  }

  // excludes other configs from attempting to handle stylable files
  (0, _webpackPlugin.applyWebpackConfigStylableExcludes)(config);
  config.plugins = config.plugins ?? [];
  config.plugins.push(new _webpackPlugin.StylableWebpackPlugin({
    assetFilter: () => false,
    filename: 'static/css/stylable.[contenthash].css',
    optimizer: stylableOptimizer
  }));
  return config;
};
exports.decorateNextJsWebpackConfig = decorateNextJsWebpackConfig;
//# sourceMappingURL=styleableDecorator.js.map