1.0.3 • Published 5 months ago

@vessp/smith v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

@vessp/smith

Installation

npm install -D @vessp/smith

Usage

package.json

  "scripts": {
    "start": "nodemon build.js -dev --watch build.js",
    "build": "node build.js"
  }

build.js

(async () => {
  const PATH = require('path')
  const isDev = process.argv.includes('-dev')

  const smith = require('@vessp/smith')({
    watch: isDev,
    srcDir: PATH.join(__dirname, 'src'),
    distDir: PATH.join(__dirname, 'dist'),

    banner: async () => ``
      + `[${process.env.npm_package_name}]`
      + `[${process.env.npm_package_version}]`
      + `[${await smith.getGitCommit()}]`
      + `[${smith.nowTs()}]`,

    define: {
      'process.env.NODE_ENV': `'${isDev ? 'development' : 'production' }'`,
    },

    alias: {
      core: PATH.resolve(__dirname, 'src', 'core'),
      components: PATH.resolve(__dirname, 'src', 'components'),
      styles: PATH.join(__dirname, 'src', 'styles'),
    },
  })

  if(isDev) smith.clearTerminal()
  console.log(`----------------[ ${process.env.npm_package_name} build.js ]-------------------`)
  await smith.cleanDist()

  await smith.bundle({
    tag: 'bundle',
    srcPath: './App.jsx',
    distPath: './bundle.js',
    assets: {
      'scss': './styles.css',
      '(woff|woff2|otf)': ({ name }) => `./fonts/${name}`,
      '(jpg|jpeg|png)': ({ name }) => `./img/${name}`,
      'svg': 'inline',
    },
    define: {
      'process.env.__b': `'pass'`,
    },
  })

  await smith.ejs({
    tag: 'index',
    srcPath: './index.ejs',
    distPath: './index.html',
    locals: async () => ({
      STYLES_HREF: '/styles.css',
      BUNDLE_HREF: '/bundle.js',
      SEED_JS: await smith.babelify({ srcPath: './seed.js' }),
      SPLASH_CSS: await smith.scssify({ srcPath: './styles/splash.scss' }),
      WIDGET_JS: '/widget.js',
      WIDGET_CSS: '/widget.css',
    }),
    watchFiles: [
      smith.srcPath('./seed.js'),
      smith.srcPath('./styles/splash.scss'),
    ],
  }) 

  await smith({
    tag: 'ssi1',
    srcPath: './header.ejs',
    distPath: './common/header.html',
  })

  await smith({
    tag: 'ssi2',
    srcPath: './header2.ejs',
    distPath: './common/header2.html',
  })

  await smith({
    tag: 'mock',
    srcPath: '../mock/foo.json',
    distPath: './foo.json',
    transformer: (text) => {
      const json = JSON.parse(text)
      json['foo'] = 'custom transformer'
      return JSON.stringify(json)
    },
  })

  await smith({
    tag: 'inline',
    code: JSON.stringify({ foo: 'inline code' }),
    distPath: './inlinefoo.json',
  })

  await smith.scss({
    tag: 'widget',
    srcPath: './styles/widget.scss',
    distPath: './widget.css',
  })

  await smith.js({
    tag: 'widget',
    srcPath: './widget.js',
    distPath: './widget.js',
  })

  if(isDev) {
    const { app } = await smith.serve({ port: 8080 })
    app.use('/mock', require('express').static(PATH.join(__dirname, 'mock')))
  }
})()
1.0.3

5 months ago

1.0.2

5 months ago

0.8.9

10 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.9.0

9 months ago

0.9.2

9 months ago

0.9.1

9 months ago

0.9.8

6 months ago

0.9.7

7 months ago

0.9.9

6 months ago

0.9.4

8 months ago

0.9.3

8 months ago

0.9.6

7 months ago

0.9.5

7 months ago

0.8.8

12 months ago

0.8.5

1 year ago

0.8.4

1 year ago

0.8.7

12 months ago

0.8.6

1 year ago

0.8.3

1 year ago

0.7.9

2 years ago

0.8.1

1 year ago

0.8.0

1 year ago

0.8.2

1 year ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.2

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.5.4

2 years ago

0.7.1

2 years ago

0.5.3

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.5.2

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.4

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago