Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/bs / src / oneConfig / PROPERTIES.ts
Size: Mime:
/**
 * Project Configuration.
 *
 * NOTE: All file/folder paths should be relative to the project root. The
 * absolute paths should be resolved during runtime by our build internal/server.
 */
import { config } from '@skava/di'
import { getEnvVariable } from '@skava/dotenv'
import { resolveToRoot } from '../resolveToRoot'
import { getCoreEnvVariables } from './getDynamicPaths'
const { bundledDependencies } = config.get('package') || {bundledDependencies: []}

/**
 * @TODO do we need to put paths also on .get ?
 */
const SCRIPT_ROOT_DIR = resolveToRoot('./dist')
const DEFAULT_DEV_PORT = process.env.IS_STANDALONE_SKREACT ? 3000 : 4444

const serverConfig = {
  // Src entry file.
  srcEntryFile: process.env.BUILD_CONFIG_SERVER_ENTRY || './src/server/index.tsx',

  // Src paths.
  srcPaths: [
    './packages',
    // './modules',
    './src',
    './src/server',
    './src/state',
    './src/views',
    './src/bootstrapper',
    './config',
  ],

  // Where does the server bundle output live?
  outputPath: SCRIPT_ROOT_DIR + '/dist/bundled/server',
}

const clientConfig = {
  srcEntryFile: process.env.BUILD_CONFIG_BROWSER_ENTRY || './src/index.tsx',

  // @NOTE important to ALSO check the paths in the `server.srcPaths`
  // Src paths.
  srcPaths: [
    // @NOTE this modules path lets babel build modules
    './packages',
    // './modules',
    './src',
    './src/client',
    './src/views',
    './src/state',
    './src/bootstrapper',
    // The service worker offline page generation needs access to the
    // config folder.  Don't worry we have guards within the config files
    // to ensure they never get included in a client bundle.
    './config',
  ],

  // Where does the client bundle output live?
  outputPath: SCRIPT_ROOT_DIR + '/dist/bundled/client',

  // What is the public http path at which we must serve the bundle from?
  webPath: process.env.WEB_PATH,

  // Configuration settings for the development vendor DLL.  This will be created
  // by our development server and provides an improved dev experience
  // by decreasing the number of modules that webpack needs to process
  // for every rebuild of our client bundle.  It by default uses the
  // dependencies configured in package.json however you can customise
  // which of these dependencies are excluded, whilst also being able to
  // specify the inclusion of additional modules below.
  devVendorDLL: {
    // Enabled?
    enabled: true,

    // Specify any dependencies that you would like to include in the
    // Vendor DLL.
    //
    // NOTE: It is also possible that some modules require specific
    // webpack loaders in order to be processed (e.g. CSS/SASS etc).
    // For these cases you don't want to include them in the Vendor DLL.
    include: bundledDependencies,
    // .concat(modulesList),

    // The name of the vendor DLL.
    name: '__dev_vendor_dll__',
  },
}

const values = {
  // The host, port, base_url, on which the server should run.
  get HOST() {
    return getCoreEnvVariables().HOST
  },
  get HAS_SSL() {
    return getCoreEnvVariables().HAS_SSL
  },
  get PORT() {
    return getCoreEnvVariables().PORT
  },
  get CLIENT_DEV_PORT() {
    return getEnvVariable('CLIENT_DEV_PORT', DEFAULT_DEV_PORT)
  },
  get CLIENT_DEV_SERVER_PORT() {
    return getEnvVariable('CLIENT_DEV_SERVER_PORT', DEFAULT_DEV_PORT)
  },
  // get BASE_URL() {
  //   // should be ${host}/${port} ...?
  //   return getCoreEnvVariables().BASE_URL
  // },
  get DISABLE_SSR() {
    return getEnvVariable('DISABLE_SSR', false)
  },
  get DISABLE_CACHE() {
    return getEnvVariable('DISABLE_CACHE', true)
  },
  get FORCE_SOURCE_MAPS() {
    return getEnvVariable('FORCE_SOURCEMAPS', false)
  },
  // @todo dedupe this
  get ABSOLUTE_URL() {
    return getEnvVariable('ABSOLUTE_URL')
    // const http = this.HAS_SSL ? 'https://' : 'http://'
    // const { PORT, HOST } = this
    // const HAS_PORT = HOST && HOST.split(':').length >= 2
    // const smartPort = PORT === 8080 || HAS_PORT ? '' : `:${PORT}`
    // const protocol = HOST && HOST.includes('http') ? '' : http
    // const ABSOLUTE_URL = `${protocol}${HOST}${smartPort}`
    // return getEnvVariable('ABSOLUTE_URL', ABSOLUTE_URL)
  },
  includeSourceMapsForOptimisedClientBundle: false,

  // The configuration values that should be exposed to our client bundle.
  // This value gets passed through the /shared/utils/objects/filterWithRules
  // util to create a filter object that can be serialised and included
  // with our client bundle.
  clientConfigFilter: {
    // This is here as an example showing that you can expose variables
    // that were potentially provivded by the environment
    // We need to expose all the htmlPage settings.
    htmlPage: true,
  },

  // How long should we set the browser cache for the served assets?
  // Don't worry, we add hashes to the files, so if they change the new files
  // will be served to browsers.
  // We are using the "ms" format to set the length.
  // @see https://www.npmjs.com/package/ms
  browserCacheMaxAge: '365d',

  // Basic configuration for the HTML page that hosts our application.
  // We make use of react-helmet to consume the values below.
  // @see https://github.com/nfl/react-helmet
  htmlPage: {
    titleTemplate: 'SkavaSTORE | %s',
    defaultTitle: 'SkavaSTORE',
    description: 'A whitelabel e-commerce platform.',
  },

  // Path to the public assets that will be served off the root of the
  // HTTP server.
  publicAssetsPath: SCRIPT_ROOT_DIR + '/assets',

  // Where does our build output live?
  buildOutputPath: SCRIPT_ROOT_DIR + '/dist',

  // THIS IS FOR ASSETS.JSON
  // @NOTE THIS IS QUITE CONFUSINGLY NAMED SINCE IT IS
  // JS BUNDLE MANIFEST DIR
  // assetsDir: SCRIPT_ROOT_DIR + '/assets',
  assetsDir: SCRIPT_ROOT_DIR + '/dist/bundled/client',

  // These extensions are tried when resolving src files for our bundles..
  //  'jsx', 'ts', 'tsx',
  bundleSrcTypes: ['js', 'json'],

  // Additional asset types to be supported for our bundles.
  // i.e. you can import the following file types within your source and the
  // webpack bundling process will bundle them with your source and create
  // URLs for them that can be resolved at runtime.
  bundleAssetTypes: [
    'jpg',
    'jpeg',
    'png',
    'gif',
    'ico',
    'eot',
    'svg',
    'ttf',
    'woff',
    'woff2',
    'otf',
  ],

  // What should we name the json output file that webpack generates
  // containing details of all output files for a bundle?
  bundleAssetsFileName: 'assets.json',

  // node_modulesList are not included in any bundles that target "node" as a
  // runtime (e.g.. the server bundle) as including them often breaks builds
  // due to thinks like require statements containing expressions..
  // However. some of the modules contain files need to be processed by
  // one of our Webpack loaders (e.g. CSS). Add any file types to the list
  // below to allow them to be processed by Webpack.
  nodeExternalsFileTypeWhitelist: [
    /\.(eot|woff|woff2|ttf|otf)$/,
    /\.(svg|png|jpg|jpeg|gif|ico)$/,
    /\.(mp4|mp3|ogg|swf|webp)$/,
    /\.(css|scss|sass|sss|less)$/,
  ],

  bundles: {
    client: clientConfig,
    server: serverConfig,
  },
}

// This protects us from accidentally including this configuration in our
// client bundle. That would be a big NO NO to do. :)
if (process.env.BUILD_FLAG_IS_CLIENT === 'true') {
  const message = `
    You shouldn't be importing the "<projectroot>/config/values.js" directly
    into code that will be included in your 'client' bundle
    as the configuration object will be sent to user's browsers.
    This could be a security risk!
    Instead, use the "config" helper function located at
    "<projectroot>/config/index.js".
  `

  throw new Error(message)
}

export default values