@io-arc/utils

Utility functions and webpack extends.

Usage#

$ npm i @io-arc/utils
index.ts
import { AssetsDirPath } from '@io-arc/utils'
const res = AssetsDirPath(['common', 'css'])

Utility Functions#

AssetsDirPath(dir)#

Returns: string

Website assets directory path.

Parameters

paramstypedefaultdescription
dirstring[]-Directory name array

example

const res = AssetsDirPath(['common', 'css'])
console.log(res)
// -> common/css

siteRootRelative(dir)#

Returns: string

Create a relative path from site root.
Site root define is SITE_ROOT.

Parameters

paramstypedefaultdescription
dirstring[]-Directory name array

example 1

default.yml
siteRoot: /
const result1 = siteRootRelative([])
// -> '/'
const result2 = siteRootRelative(['abc', 'def'])
// -> '/abc/def/'

example 2

default.yml
siteRoot: /foo/
const result1 = siteRootRelative([])
// -> '/foo/'
const result2 = siteRootRelative(['abc', 'def'])
// -> '/foo/abc/def/'

Webpack extends Methods#

Extend build of HTML, CSS, JavaScript.
See settings.

webpack.config.ts
import { WebpackExtend } from '@io-arc/utils'
// User extends
const extend = new WebpackExtend('js')
const externals = extend.externals()
const extendsLoaders = extend.loaders() || []
const extendPlugins = extend.plugins() || []
export default {
// (abbreviation)
externals: externals,
module: {
rules: [...extendsLoaders]
},
plugins: [...plugins]
}

Instance parameters#

paramstypedefaultdescription
targethtml | css | js-Specify a property that exists in webpack.extends.js

data()#

Returns: object(*) | null

* Return object
import { ExternalsElement, RuleSetRule, Plugin } from 'webpack'
interface IfWebpackExtend {
externals?: ExternalsElement | ExternalsElement[]
loaders?: RuleSetRule[]
plugins?: Plugin[]
[key: string]: any
}

Get all information in the specified target.

externals()#

Return: ExternalsElement | ExternalsElement[]
See webpack#externals.

loaders()#

Returns: RuleSetRule[]
See webpack#rule.

plugins()#

Returns: Plugin[]
See webpack#plugins