UNPKG

@demouth/mb_strwidth

Version:

Calculates the width of a string, where halfwidth characters count as 1, and fullwidth characters count as 2.

128 lines (121 loc) 2.81 kB
import { terser as pluginTerser } from 'rollup-plugin-terser'; import pluginTypescript from '@rollup/plugin-typescript'; import pluginCommonjs from '@rollup/plugin-commonjs'; import pluginNodeResolve from '@rollup/plugin-node-resolve'; import { babel as pluginBabel } from '@rollup/plugin-babel'; import * as path from 'path'; import pkg from './package.json'; const moduleName = pkg.name.replace(/^@.*\//, ''); const inputFileName = 'src/index.ts'; const inputFileNameForBrowser = 'src/mb_strwidth.ts'; const banner = `/** * @license * ${moduleName}.js v${pkg.version} * Released under the ${pkg.license} License. */`; export default [ // browser { input: inputFileNameForBrowser, output: [ // uncompressed { name: moduleName, file: pkg.browser, format: 'iife', sourcemap: 'inline', banner }, // minified { name: moduleName, file: pkg.browser.replace('.js', '.min.js'), format: 'iife', sourcemap: 'inline', banner, plugins: [ pluginTerser(), ], } ], plugins: [ pluginTypescript({ tsconfig: './tsconfig.json' }), pluginCommonjs({ extensions: ['.js', '.ts'], }), pluginBabel({ babelHelpers: 'bundled', configFile: path.resolve(__dirname, '.babelrc.js'), }), pluginNodeResolve({ browser: true, }), ], }, // ES Module { input: inputFileName, output: [ { file: pkg.module, format: 'es', sourcemap: 'inline', banner, exports: 'named', }, ], external: [ ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {}), ], plugins: [ pluginTypescript({ tsconfig: './tsconfig.json' }), pluginCommonjs({ extensions: ['.js', '.ts'], }), pluginBabel({ babelHelpers: 'bundled', configFile: path.resolve(__dirname, '.babelrc.js'), }), pluginNodeResolve({ browser: false, }), ], }, // CommonJS { input: inputFileName, output: [ { file: pkg.main, format: 'cjs', sourcemap: 'inline', banner, exports: 'named', }, ], external: [ ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {}), ], plugins: [ pluginTypescript({ tsconfig: './tsconfig.json' }), pluginCommonjs({ extensions: ['.js', '.ts'], }), pluginBabel({ babelHelpers: 'bundled', configFile: path.resolve(__dirname, '.babelrc.js'), }), pluginNodeResolve({ browser: false, }), ], }, ];