mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 20:08:59 +08:00
add more build files
This commit is contained in:
parent
c0e08fef40
commit
d8c94d09f1
@ -1,165 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const zlib = require('zlib')
|
|
||||||
const uglify = require('uglify-js')
|
|
||||||
const rollup = require('rollup')
|
|
||||||
// const configs = require('./configs')
|
|
||||||
|
|
||||||
const buble = require('rollup-plugin-buble')
|
|
||||||
const flow = require('rollup-plugin-flow-no-whitespace')
|
|
||||||
const cjs = require('rollup-plugin-commonjs')
|
|
||||||
const node = require('rollup-plugin-node-resolve')
|
|
||||||
const replace = require('rollup-plugin-replace')
|
|
||||||
|
|
||||||
const vue = require('rollup-plugin-vue')
|
|
||||||
const babel = require('rollup-plugin-babel')
|
|
||||||
|
|
||||||
// const resolveee = require('rollup-plugin-node-resolve')
|
|
||||||
|
|
||||||
// console.log('looool', VuePlugin)
|
|
||||||
|
|
||||||
const version = require('../package.json').version
|
|
||||||
const banner =
|
|
||||||
`/*!
|
|
||||||
* tiptap v${version}
|
|
||||||
* (c) ${new Date().getFullYear()} Philipp Kühn
|
|
||||||
* @license MIT
|
|
||||||
*/`
|
|
||||||
|
|
||||||
|
|
||||||
const resolve = _path => path.resolve(__dirname, '../', _path)
|
|
||||||
|
|
||||||
console.log(resolve('src/index.js'))
|
|
||||||
|
|
||||||
function genConfig(opts) {
|
|
||||||
const config = {
|
|
||||||
input: {
|
|
||||||
input: resolve('src/index.js'),
|
|
||||||
plugins: [
|
|
||||||
// resolveee({
|
|
||||||
// extensions: [ '.mjs', '.js', '.jsx', '.json' ],
|
|
||||||
// }),
|
|
||||||
// vue.default(),
|
|
||||||
// flow(),
|
|
||||||
// babel(),
|
|
||||||
node({
|
|
||||||
extensions: [ '.mjs', '.js', '.jsx', '.json' ],
|
|
||||||
}),
|
|
||||||
// cjs(),
|
|
||||||
// buble(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
file: opts.file,
|
|
||||||
format: opts.format,
|
|
||||||
banner,
|
|
||||||
name: 'tiptap',
|
|
||||||
},
|
|
||||||
external: [ 'vue', 'prosemirror-model' ]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.env) {
|
|
||||||
config.input.plugins.unshift(replace({
|
|
||||||
'process.env.NODE_ENV': JSON.stringify(opts.env)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync('dist')) {
|
|
||||||
fs.mkdirSync('dist')
|
|
||||||
}
|
|
||||||
|
|
||||||
const configs = [
|
|
||||||
// browser dev
|
|
||||||
{
|
|
||||||
file: resolve('dist/tiptap.js'),
|
|
||||||
format: 'umd',
|
|
||||||
env: 'development'
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// file: resolve('dist/tiptap.min.js'),
|
|
||||||
// format: 'umd',
|
|
||||||
// env: 'production'
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// file: resolve('dist/tiptap.common.js'),
|
|
||||||
// format: 'cjs'
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// file: resolve('dist/tiptap.esm.js'),
|
|
||||||
// format: 'es'
|
|
||||||
// }
|
|
||||||
].map(genConfig)
|
|
||||||
|
|
||||||
function build (builds) {
|
|
||||||
let built = 0
|
|
||||||
const total = builds.length
|
|
||||||
const next = () => {
|
|
||||||
buildEntry(builds[built]).then(() => {
|
|
||||||
built++
|
|
||||||
if (built < total) {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}).catch(logError)
|
|
||||||
}
|
|
||||||
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildEntry ({ input, output }) {
|
|
||||||
const isProd = /min\.js$/.test(output.file)
|
|
||||||
return rollup.rollup(input)
|
|
||||||
.then(bundle => bundle.generate(output))
|
|
||||||
.then(({ code }) => {
|
|
||||||
if (isProd) {
|
|
||||||
const minified = uglify.minify(code, {
|
|
||||||
output: {
|
|
||||||
preamble: output.banner,
|
|
||||||
/* eslint-disable camelcase */
|
|
||||||
ascii_only: true
|
|
||||||
/* eslint-enable camelcase */
|
|
||||||
}
|
|
||||||
}).code
|
|
||||||
return write(output.file, minified, true)
|
|
||||||
} else {
|
|
||||||
return write(output.file, code)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function write (dest, code, zip) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
function report (extra) {
|
|
||||||
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
|
|
||||||
resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFile(dest, code, err => {
|
|
||||||
if (err) return reject(err)
|
|
||||||
if (zip) {
|
|
||||||
zlib.gzip(code, (err, zipped) => {
|
|
||||||
if (err) return reject(err)
|
|
||||||
report(' (gzipped: ' + getSize(zipped) + ')')
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
report()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSize (code) {
|
|
||||||
return (code.length / 1024).toFixed(2) + 'kb'
|
|
||||||
}
|
|
||||||
|
|
||||||
function logError (e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
function blue (str) {
|
|
||||||
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
|
|
||||||
}
|
|
||||||
|
|
||||||
build(configs)
|
|
78
build/package/build.js
Normal file
78
build/package/build.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import zlib from 'zlib'
|
||||||
|
import uglify from 'uglify-js'
|
||||||
|
import { rollup } from 'rollup'
|
||||||
|
import config from './config'
|
||||||
|
|
||||||
|
if (!fs.existsSync('dist')) {
|
||||||
|
fs.mkdirSync('dist')
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSize(code) {
|
||||||
|
return `${(code.length / 1024).toFixed(2)}kb`
|
||||||
|
}
|
||||||
|
|
||||||
|
function logError(e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
function blue(str) {
|
||||||
|
return `\x1b[1m\x1b[34m${str}\x1b[39m\x1b[22m`
|
||||||
|
}
|
||||||
|
|
||||||
|
function write(dest, code, zip) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
function report(extra) {
|
||||||
|
console.log(`${blue(path.relative(process.cwd(), dest)) } ${getSize(code) }${extra || ''}`)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFile(dest, code, error => {
|
||||||
|
if (error) return reject(error)
|
||||||
|
if (zip) {
|
||||||
|
zlib.gzip(code, (err, zipped) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
report(` (gzipped: ${getSize(zipped)})`)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
report()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildEntry({ input, output }) {
|
||||||
|
const isProd = /min\.js$/.test(output.file)
|
||||||
|
return rollup(input)
|
||||||
|
.then(bundle => bundle.generate(output))
|
||||||
|
.then(({ code }) => {
|
||||||
|
if (isProd) {
|
||||||
|
const minified = uglify.minify(code, {
|
||||||
|
output: {
|
||||||
|
preamble: output.banner,
|
||||||
|
ascii_only: true,
|
||||||
|
},
|
||||||
|
}).code
|
||||||
|
return write(output.file, minified, true)
|
||||||
|
}
|
||||||
|
return write(output.file, code)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function build(builds) {
|
||||||
|
let built = 0
|
||||||
|
const total = builds.length
|
||||||
|
const next = () => {
|
||||||
|
buildEntry(builds[built]).then(() => {
|
||||||
|
built++
|
||||||
|
if (built < total) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(logError)
|
||||||
|
}
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
build(config)
|
78
build/package/config.js
Normal file
78
build/package/config.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import path from 'path'
|
||||||
|
import vue from 'rollup-plugin-vue'
|
||||||
|
import buble from 'rollup-plugin-buble'
|
||||||
|
import flow from 'rollup-plugin-flow-no-whitespace'
|
||||||
|
import cjs from 'rollup-plugin-commonjs'
|
||||||
|
import node from 'rollup-plugin-node-resolve'
|
||||||
|
import replace from 'rollup-plugin-replace'
|
||||||
|
import packagejson from '../../package.json'
|
||||||
|
|
||||||
|
const { version } = packagejson
|
||||||
|
const banner = `
|
||||||
|
/*!
|
||||||
|
* tiptap v${version}
|
||||||
|
* (c) ${new Date().getFullYear()} Scrumpy UG (limited liability)
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
`
|
||||||
|
|
||||||
|
const resolve = _path => path.resolve(__dirname, '../../', _path)
|
||||||
|
|
||||||
|
function genConfig(opts) {
|
||||||
|
const config = {
|
||||||
|
input: {
|
||||||
|
input: resolve('src/index.js'),
|
||||||
|
plugins: [
|
||||||
|
flow(),
|
||||||
|
node(),
|
||||||
|
cjs(),
|
||||||
|
vue({
|
||||||
|
css: true,
|
||||||
|
compileTemplate: true,
|
||||||
|
}),
|
||||||
|
replace({
|
||||||
|
__VERSION__: version,
|
||||||
|
}),
|
||||||
|
buble({
|
||||||
|
objectAssign: 'Object.assign',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
external: ['vue'],
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
file: opts.file,
|
||||||
|
format: opts.format,
|
||||||
|
banner,
|
||||||
|
name: 'tiptap',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts.env) {
|
||||||
|
config.input.plugins.unshift(replace({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify(opts.env),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
file: resolve('dist/tiptap.js'),
|
||||||
|
format: 'umd',
|
||||||
|
env: 'development',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: resolve('dist/tiptap.min.js'),
|
||||||
|
format: 'umd',
|
||||||
|
env: 'production',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: resolve('dist/tiptap.common.js'),
|
||||||
|
format: 'cjs',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: resolve('dist/tiptap.esm.js'),
|
||||||
|
format: 'es',
|
||||||
|
},
|
||||||
|
].map(genConfig)
|
@ -1,27 +0,0 @@
|
|||||||
import vue from 'rollup-plugin-vue'
|
|
||||||
import buble from 'rollup-plugin-buble'
|
|
||||||
import cjs from 'rollup-plugin-commonjs'
|
|
||||||
import resolve from 'rollup-plugin-node-resolve'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
input: 'src/index.js',
|
|
||||||
output: {
|
|
||||||
name: 'tiptap',
|
|
||||||
exports: 'named',
|
|
||||||
format: 'cjs',
|
|
||||||
file: 'dist/tiptap.min.js',
|
|
||||||
},
|
|
||||||
sourcemap: true,
|
|
||||||
plugins: [
|
|
||||||
resolve(),
|
|
||||||
cjs(),
|
|
||||||
vue({
|
|
||||||
css: true,
|
|
||||||
compileTemplate: true,
|
|
||||||
}),
|
|
||||||
buble({
|
|
||||||
objectAssign: 'Object.assign',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
external: ['vue'],
|
|
||||||
}
|
|
17
package.json
17
package.json
@ -1,20 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "tiptap",
|
"name": "tiptap",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"description": "A rich-text editor for Vue.js",
|
"description": "A rich-text editor for Vue.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/tiptap.min.js",
|
"main": "dist/tiptap.common.js",
|
||||||
|
"module": "dist/tiptap.esm.js",
|
||||||
|
"unpkg": "dist/tiptap.js",
|
||||||
|
"jsdelivr": "dist/tiptap.js",
|
||||||
|
"sideEffects": false,
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
|
"keywords": [
|
||||||
|
"vue",
|
||||||
|
"editor",
|
||||||
|
"rich-text",
|
||||||
|
"prosemirror",
|
||||||
|
"wysiwyg"
|
||||||
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/heyscrumpy/tiptap.git"
|
"url": "git+https://github.com/heyscrumpy/tiptap.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "./node_modules/@babel/node/bin/babel-node.js build/examples/server.js --env=development",
|
"start": "./node_modules/@babel/node/bin/babel-node.js build/examples/server.js --env=development",
|
||||||
"build:package": "rollup --config build/package/rollup.config.js",
|
"build:package": "./node_modules/@babel/node/bin/babel-node.js build/package/build.js",
|
||||||
"build:examples": "./node_modules/@babel/node/bin/babel-node.js build/examples/build.js --env=production"
|
"build:examples": "./node_modules/@babel/node/bin/babel-node.js build/examples/build.js --env=production"
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
|
Loading…
Reference in New Issue
Block a user