1.1.8 • Published 4 months ago

voltranjs v1.1.8

Weekly downloads
18
License
-
Repository
github
Last release
4 months ago

Key Features

You can use Voltran if you need a micro frontend framework that provides following features:

  • Lightweight and fast API
  • Serves single and multiple components
  • Preview (to visualize components)
  • SEO friendly (if needed)
  • CSS & SCSS support
  • Supports only React (for now)

Installation

Voltran requires Node.js v10.15.0+ to run.

Install the Voltran.

Yarn

$ yarn add voltranjs

Npm

$ npm install voltranjs

Usage

This is an example component.

First of all, you should import @voltran/core.

After that we can write the component's code.

HelloWorld.js

const voltran = require('@voltran/core');

import React from 'react';

const ROUTE_PATHS = {
  HELLOWORLDPAGE: '/HelloWorld'
};

const HelloWorld = ({ initialState }) => {
  return <>Hello World!</>;
};

const component = voltran.default.withBaseComponent(HelloWorld, ROUTE_PATHS.HELLOWORLDPAGE);

export default component;

If you want to fetch data from server side, you should add getInitialState.

./conf/local.config.js

const port = 3578;

module.exports = {
  port: port,
  baseUrl: `http://localhost:${port}`,
  mediaUrl: '',
  services: {
    voltranapi: {
      clientUrl: 'http://voltran-api.qa.hepsiburada.com',
      serverUrl: 'http://voltran-api.qa.hepsiburada.com'
    }
  },
  timeouts: {
    clientApiManager: 20 * 1000,
    serverApiManager: 20 * 1000
  }
};

HelloWorld.js

const voltran = require('@voltran/core');

import React from 'react';
import appConfig from '../appConfig';

const ROUTE_PATHS = {
  HELLOWORLDPAGE: '/HelloWorld',
};

const HelloWorld = ({initialState}) => {
    HelloWorld.services = [appConfig.services.voltranApi];

    HelloWorld.getInitialState = (voltranApiClientManager, context) => {
      const config = { headers: context.headers };
      const params = {...};

      return getName({ params }, voltranApiClientManager, config);
    };

    return (
        <>
            Hello World. My name is {initialState.name}!
        </>
    );
};

const component = voltran.default.withBaseComponent(HelloWorld, ROUTE_PATHS.HELLOWORLDPAGE);

export default component;

Output For Preview

Hello World. My Name is Volkan!

Output For Api

{
    html: ...,
    scripts: [...],
    style: [...],
    activeComponent: {
        resultPath: "/HelloWorld",
        componentName: "HelloWorld",
        url: "/HelloWorld"
    },
}

Configs

Voltran requires following configurations:

ConfigType
appConfigFileObject
devBoolean
distFolderString
publicDistFolderString
inputFolderString * required
monitoringObject
portNumber - String
prefixString * required
ssrString
stylesArray
outputObject
staticPropsArray
routingObject
webpackConfigurationObject
sassResourcesArray
criticalCssDisabledBoolean

appConfigFile

It should contain environment specific configurations (test, production ...).

appConfigFile: {
  entry: path.resolve(__dirname, './yourConfigFolder/'),
  output: {
    path: path.resolve(__dirname, './yourOutputFolder/'),
    name: 'yourFileName',
  }
}

dev

Development mode. Set to true if you need to debug.

Default: false

distFolder

The path to the folder where bundled scripts will be placed after the build.

Default: ./dist

publicDistFolder

The path to the folder where asset files will be placed after the build.

Default: ./dist/assets

inputFolder

The path to the folder that contains script files. It's required.

Passes this config to Babel Loader where it reads all js files under this folder.

'Voltran' converts your files to the appropriate format and optimizes them.

monitoring

For now, only prometheus is supported.

monitoring: {
  prometheus: false
}

or you can set your custom js file.

monitoring: {
    prometheus: path.resolve(__dirname, './src/tools/prometheus.js')
}

port

Default: 3578

If you want to change the port you may need to change the port in appConfigFiles

prefix

It is required.

There may be different components owned by different teams using voltrans on the same page. Voltran needs to use a prefix in order to avoid conflicts issues. This prefix is prepended to initial states and CSS class names.

We recommend that each team use their own acronyms/prefixes.

ssr

Default: true Voltran supports server side rendering. Applications that need 'SEO' features needs to set this parameter to true.

styles

This field's value should be an array of strings. Array values should be the paths to the global CSS files.

styles: [
    path.resolve(__dirname, './some-css-file.scss'),
    path.resolve(__dirname, './node_modules/carousel/carousel.css')
]

output

output: {
  client: {
    path: path.resolve(__dirname, './build/public/project/assets'),
    publicPath: path.resolve(__dirname, './src/assets'),
    filename: '[name]-[contenthash].js',
    chunkFilename: '[name]-[chunkhash].js'
  },
  server: {
    path: path.resolve(__dirname, './build/server'),
    filename: '[name].js'
  },
},

staticProps

You can pass static props to all components at the same time.

staticProps: [
  {'key': value}
]

routing

Voltran need two files to set routing.

routing: {
  components: path.resolve(__dirname, './src/appRoute/components.js'),
  dictionary: path.resolve(__dirname, './src/appRoute/dictionary.js')
}

criticalCssDisabled

Set to false if don't need to critical styles.

Default: true

Example files can be found here:

webpackConfiguration

You can add your webpack configuration. They will be merged with the voltran configs.

You can access the starter kit we created from the link.

sassResources

You can add sass resources to this field as string array. sass-resource-loader gonna inject those files in every sass files so you won't need to import them.

You can check sass-resource-loader for usage.

New Relic Integration

Add newrelicEnabled: true on your config.

If you throw an error like throw new Error({message: "Service error", code: 500}) from your fragments, Voltran detects the fields and sends each field to New Relic as a custom attribute. These fields appear with _a prefix to place in the first of rows on your new relic.

Tech

Voltran uses a number of open source projects to work properly:

  • ReactJS - A JavaScript library for building user interfaces!
  • Webpack - Module bundler
  • babel - The compiler for next generation JavaScript.
  • node.js - evented I/O for the backend
  • hiddie - fast node.js network app framework (friendly fork of middie)
  • Yarn - the streaming build system

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request
1.1.8

6 months ago

1.1.7

6 months ago

1.2.0-beta.20

4 months ago

1.2.0-beta.18

5 months ago

1.2.0-beta.19

5 months ago

1.2.0-beta.17

11 months ago

1.1.6

1 year ago

1.2.0-beta.16

12 months ago

1.2.0-beta.15

1 year ago

1.2.0-beta.12

1 year ago

1.2.0-beta.14

1 year ago

1.2.0-beta.13

1 year ago

1.2.0-beta.9

1 year ago

1.2.0-beta.8

1 year ago

1.2.0-beta.11

1 year ago

1.2.0-beta.10

1 year ago

1.2.0-beta.5

2 years ago

1.2.0-beta.4

2 years ago

1.2.0-beta.7

2 years ago

1.2.0-beta.6

2 years ago

1.1.5

2 years ago

1.2.0-beta.3

2 years ago

1.1.4

2 years ago

1.2.0-beta.1

2 years ago

1.2.0-beta.0

2 years ago

1.2.0-beta.2

2 years ago

1.1.0-beta.18

3 years ago

1.1.0-beta.19

3 years ago

1.1.0-beta.16

3 years ago

1.1.0-beta.17

3 years ago

1.1.0-beta.21

3 years ago

1.1.0-beta.22

3 years ago

1.1.0-beta.20

3 years ago

1.1.0-beta.23

3 years ago

1.1.0-beta.24

3 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.0-beta.10

3 years ago

1.1.0-beta.11

3 years ago

1.1.0-beta.14

3 years ago

1.1.0-beta.15

3 years ago

1.1.0-beta.12

3 years ago

1.1.0-beta.13

3 years ago

1.1.0-beta.9

3 years ago

1.1.0-beta.8

3 years ago

1.1.0-beta.7

3 years ago

1.1.0-beta.2

3 years ago

1.1.0-beta.1

3 years ago

1.1.0-beta.0

3 years ago

1.1.0-beta.6

3 years ago

1.1.0-beta.4

3 years ago

1.1.0-beta.3

3 years ago

1.0.26

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago