mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 20:08:59 +08:00
add broken rollup build
This commit is contained in:
parent
0e75610fcd
commit
4a8b85d250
@ -65,8 +65,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import Icon from 'Components/Icon'
|
import Icon from 'Components/Icon'
|
||||||
import { Editor } from 'tiptap'
|
import { Editor } from 'tiptap'
|
||||||
|
// import tiptap from 'tiptap'
|
||||||
|
// import tiptap from '../dist/tiptap.min.js'
|
||||||
import MentionPlugin from './plugins/Mention.js'
|
import MentionPlugin from './plugins/Mention.js'
|
||||||
|
|
||||||
|
// console.log(tiptap)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Editor,
|
Editor,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import 'babel-polyfill'
|
import '@babel/polyfill'
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import svgSpriteLoader from 'helpers/svg-sprite-loader'
|
import svgSpriteLoader from 'helpers/svg-sprite-loader'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
46
package.json
46
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tiptap",
|
"name": "tiptap",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"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.min.js",
|
||||||
@ -13,17 +13,17 @@
|
|||||||
"url": "git+https://github.com/heyscrumpy/tiptap.git"
|
"url": "git+https://github.com/heyscrumpy/tiptap.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "babel-node webpack/server.js --env=development",
|
"r": "rollup -c",
|
||||||
"build:package": "babel-node webpack/build.package.js --env=production",
|
"start": "./node_modules/@babel/node/bin/babel-node.js webpack/server.js --env=development",
|
||||||
"build:examples": "babel-node webpack/build.examples.js --env=production"
|
"build:package": "./node_modules/@babel/node/bin/babel-node.js webpack/build.package.js --env=production",
|
||||||
|
"build:examples": "./node_modules/@babel/node/bin/babel-node.js webpack/build.examples.js --env=production"
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
"presets": [
|
"presets": [
|
||||||
"stage-2",
|
[
|
||||||
"env"
|
"@babel/preset-env"
|
||||||
],
|
]
|
||||||
"comments": false,
|
]
|
||||||
"compact": true
|
|
||||||
},
|
},
|
||||||
"postcss": {
|
"postcss": {
|
||||||
"plugins": {
|
"plugins": {
|
||||||
@ -36,16 +36,16 @@
|
|||||||
"ie >= 9"
|
"ie >= 9"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.0.0-rc.2",
|
||||||
|
"@babel/node": "^7.0.0-rc.2",
|
||||||
|
"@babel/plugin-transform-runtime": "^7.0.0-rc.2",
|
||||||
|
"@babel/polyfill": "^7.0.0-rc.2",
|
||||||
|
"@babel/preset-env": "^7.0.0-rc.2",
|
||||||
|
"@babel/preset-stage-2": "^7.0.0-rc.2",
|
||||||
|
"@babel/runtime": "^7.0.0-rc.2",
|
||||||
"autoprefixer": "^9.1.1",
|
"autoprefixer": "^9.1.1",
|
||||||
"babel-cli": "^6.24.1",
|
|
||||||
"babel-core": "^6.26.3",
|
|
||||||
"babel-eslint": "^8.2.5",
|
"babel-eslint": "^8.2.5",
|
||||||
"babel-loader": "^7.1.5",
|
"babel-loader": "^8.0.0-beta.6",
|
||||||
"babel-plugin-transform-runtime": "^6.23.0",
|
|
||||||
"babel-polyfill": "^6.26.0",
|
|
||||||
"babel-preset-env": "^1.7.0",
|
|
||||||
"babel-preset-stage-2": "^6.24.1",
|
|
||||||
"babel-runtime": "^6.25.0",
|
|
||||||
"browser-sync": "^2.24.5",
|
"browser-sync": "^2.24.5",
|
||||||
"copy-webpack-plugin": "^4.5.2",
|
"copy-webpack-plugin": "^4.5.2",
|
||||||
"css-loader": "^1.0.0",
|
"css-loader": "^1.0.0",
|
||||||
@ -68,8 +68,17 @@
|
|||||||
"postcss": "^7.0.2",
|
"postcss": "^7.0.2",
|
||||||
"postcss-loader": "^3.0.0",
|
"postcss-loader": "^3.0.0",
|
||||||
"postcss-scss": "^2.0.0",
|
"postcss-scss": "^2.0.0",
|
||||||
|
"rollup": "^0.64.1",
|
||||||
|
"rollup-plugin-babel": "^4.0.0-beta.8",
|
||||||
|
"rollup-plugin-buble": "^0.19.2",
|
||||||
|
"rollup-plugin-commonjs": "^9.1.5",
|
||||||
|
"rollup-plugin-flow-no-whitespace": "^1.0.0",
|
||||||
|
"rollup-plugin-node-resolve": "^3.3.0",
|
||||||
|
"rollup-plugin-replace": "^2.0.0",
|
||||||
|
"rollup-plugin-vue": "^4.3.2",
|
||||||
"sass-loader": "^7.0.3",
|
"sass-loader": "^7.0.3",
|
||||||
"style-loader": "^0.22.1",
|
"style-loader": "^0.22.1",
|
||||||
|
"uglify-js": "^3.4.7",
|
||||||
"vue": "^2.5.17",
|
"vue": "^2.5.17",
|
||||||
"vue-loader": "^15.2.4",
|
"vue-loader": "^15.2.4",
|
||||||
"vue-style-loader": "^4.1.0",
|
"vue-style-loader": "^4.1.0",
|
||||||
@ -78,7 +87,8 @@
|
|||||||
"webpack-dev-middleware": "^3.1.3",
|
"webpack-dev-middleware": "^3.1.3",
|
||||||
"webpack-hot-middleware": "^2.22.2",
|
"webpack-hot-middleware": "^2.22.2",
|
||||||
"webpack-manifest-plugin": "^2.0.3",
|
"webpack-manifest-plugin": "^2.0.3",
|
||||||
"webpack-svgstore-plugin": "^4.0.3"
|
"webpack-svgstore-plugin": "^4.0.3",
|
||||||
|
"zlib": "^1.0.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"prosemirror-commands": "^1.0.7",
|
"prosemirror-commands": "^1.0.7",
|
||||||
|
18
rollup.config.js
Normal file
18
rollup.config.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module.exports = {
|
||||||
|
input: "./src/index.js",
|
||||||
|
output: {format: "cjs", file: "dist/tiptap.min.js"},
|
||||||
|
sourcemap: true,
|
||||||
|
plugins: [
|
||||||
|
// require("rollup-plugin-buble")(),
|
||||||
|
// require('rollup-plugin-commonjs')(),
|
||||||
|
require('rollup-plugin-babel')({
|
||||||
|
babelrc: false,
|
||||||
|
presets: [['@babel/preset-env', { modules: false }]]
|
||||||
|
}),
|
||||||
|
require('rollup-plugin-node-resolve')()
|
||||||
|
],
|
||||||
|
buble: {
|
||||||
|
objectAssign: 'Object.assign'
|
||||||
|
},
|
||||||
|
external(id) { return !/^[\.\/]/.test(id) }
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
<script>
|
|
||||||
import { EditorState, Plugin } from 'prosemirror-state'
|
import { EditorState, Plugin } from 'prosemirror-state'
|
||||||
import { EditorView } from 'prosemirror-view'
|
import { EditorView } from 'prosemirror-view'
|
||||||
import { Schema, DOMParser } from 'prosemirror-model'
|
import { Schema, DOMParser } from 'prosemirror-model'
|
||||||
@ -217,4 +216,3 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
|
@ -1,5 +1,5 @@
|
|||||||
import { setBlockType } from 'prosemirror-commands'
|
import { setBlockType } from 'prosemirror-commands'
|
||||||
import { nodeIsActive } from 'tiptap/utils'
|
import { nodeIsActive } from '../utils'
|
||||||
|
|
||||||
export default function (type, toggletype, attrs = {}) {
|
export default function (type, toggletype, attrs = {}) {
|
||||||
return (state, dispatch, view) => {
|
return (state, dispatch, view) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { nodeIsActive } from 'tiptap/utils'
|
import { nodeIsActive } from '../utils'
|
||||||
import { wrapInList, liftListItem } from 'tiptap/helpers'
|
import { wrapInList, liftListItem } from '../helpers'
|
||||||
|
|
||||||
export default function toggleList(type, itemType) {
|
export default function toggleList(type, itemType) {
|
||||||
return (state, dispatch, view) => {
|
return (state, dispatch, view) => {
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
import Editor from './components/editor.vue'
|
import Editor from './components/editor'
|
||||||
|
|
||||||
export { Editor }
|
export { Editor }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Mark } from 'tiptap/utils'
|
import { Mark } from '../utils'
|
||||||
import { toggleMark } from 'tiptap/helpers'
|
import { toggleMark } from '../helpers'
|
||||||
|
|
||||||
export default class BoldMark extends Mark {
|
export default class BoldMark extends Mark {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Mark } from 'tiptap/utils'
|
import { Mark } from '../utils'
|
||||||
import { toggleMark } from 'tiptap/helpers'
|
import { toggleMark } from '../helpers'
|
||||||
|
|
||||||
export default class CodeMark extends Mark {
|
export default class CodeMark extends Mark {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Mark } from 'tiptap/utils'
|
import { Mark } from '../utils'
|
||||||
import { toggleMark } from 'tiptap/helpers'
|
import { toggleMark } from '../helpers'
|
||||||
|
|
||||||
export default class ItalicMark extends Mark {
|
export default class ItalicMark extends Mark {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Mark } from 'tiptap/utils'
|
import { Mark } from '../utils'
|
||||||
import { updateMark, removeMark } from 'tiptap/helpers'
|
import { updateMark, removeMark } from '../helpers'
|
||||||
|
|
||||||
export default class LinkMark extends Mark {
|
export default class LinkMark extends Mark {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { wrappingInputRule, setBlockType, wrapIn } from 'tiptap/helpers'
|
import { wrappingInputRule, setBlockType, wrapIn } from '../helpers'
|
||||||
|
|
||||||
export default class BlockquoteNode extends Node {
|
export default class BlockquoteNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { wrappingInputRule, wrapInList, toggleList } from 'tiptap/helpers'
|
import { wrappingInputRule, wrapInList, toggleList } from '../helpers'
|
||||||
|
|
||||||
export default class BulletNode extends Node {
|
export default class BulletNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { toggleBlockType, setBlockType, textblockTypeInputRule } from 'tiptap/helpers'
|
import { toggleBlockType, setBlockType, textblockTypeInputRule } from '../helpers'
|
||||||
|
|
||||||
export default class CodeBlockNode extends Node {
|
export default class CodeBlockNode extends Node {
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
|
|
||||||
export default class DocNode extends Node {
|
export default class DocNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { chainCommands, exitCode } from 'tiptap/helpers'
|
import { chainCommands, exitCode } from '../helpers'
|
||||||
|
|
||||||
export default class HardBreakNode extends Node {
|
export default class HardBreakNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { setBlockType, textblockTypeInputRule, toggleBlockType } from 'tiptap/helpers'
|
import { setBlockType, textblockTypeInputRule, toggleBlockType } from '../helpers'
|
||||||
|
|
||||||
export default class HeadingNode extends Node {
|
export default class HeadingNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { splitListItem, liftListItem, sinkListItem } from 'tiptap/helpers'
|
import { splitListItem, liftListItem, sinkListItem } from '../helpers'
|
||||||
|
|
||||||
export default class OrderedListNode extends Node {
|
export default class OrderedListNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { wrappingInputRule, wrapInList, toggleList } from 'tiptap/helpers'
|
import { wrappingInputRule, wrapInList, toggleList } from '../helpers'
|
||||||
|
|
||||||
export default class OrderedListNode extends Node {
|
export default class OrderedListNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { setBlockType } from 'tiptap/helpers'
|
import { setBlockType } from '../helpers'
|
||||||
|
|
||||||
export default class ParagraphNode extends Node {
|
export default class ParagraphNode extends Node {
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
|
|
||||||
export default class TextNode extends Node {
|
export default class TextNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { splitListItem, liftListItem } from 'tiptap/helpers'
|
import { splitListItem, liftListItem } from '../helpers'
|
||||||
|
|
||||||
export default class TodoItemNode extends Node {
|
export default class TodoItemNode extends Node {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Node } from 'tiptap/utils'
|
import { Node } from '../utils'
|
||||||
import { wrapInList, wrappingInputRule } from 'tiptap/helpers'
|
import { wrapInList, wrappingInputRule } from '../helpers'
|
||||||
|
|
||||||
export default class BulletNode extends Node {
|
export default class BulletNode extends Node {
|
||||||
|
|
||||||
|
@ -8,13 +8,19 @@ export default function ({ schema, state, commands }) {
|
|||||||
const command = commands[name] ? commands[name] : () => {}
|
const command = commands[name] ? commands[name] : () => {}
|
||||||
return { name, active, command }
|
return { name, active, command }
|
||||||
})
|
})
|
||||||
.reduce((actions, { name, active, command }) => ({
|
.reduce((actions, { name, active, command }) => Object.assign({}, actions, {
|
||||||
...actions,
|
|
||||||
[name]: {
|
[name]: {
|
||||||
active,
|
active,
|
||||||
command,
|
command,
|
||||||
},
|
},
|
||||||
}), {})
|
}), {})
|
||||||
|
// .reduce((actions, { name, active, command }) => ({
|
||||||
|
// ...actions,
|
||||||
|
// [name]: {
|
||||||
|
// active,
|
||||||
|
// command,
|
||||||
|
// },
|
||||||
|
// }), {})
|
||||||
|
|
||||||
const marks = Object.entries(schema.marks)
|
const marks = Object.entries(schema.marks)
|
||||||
.map(([name]) => {
|
.map(([name]) => {
|
||||||
@ -28,14 +34,21 @@ export default function ({ schema, state, commands }) {
|
|||||||
command,
|
command,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.reduce((actions, { name, active, attrs, command }) => ({
|
.reduce((actions, { name, active, attrs, command }) => Object.assign({}, actions, {
|
||||||
...actions,
|
|
||||||
[name]: {
|
[name]: {
|
||||||
active,
|
active,
|
||||||
attrs,
|
attrs,
|
||||||
command,
|
command,
|
||||||
},
|
},
|
||||||
}), {})
|
}), {})
|
||||||
|
// .reduce((actions, { name, active, attrs, command }) => ({
|
||||||
|
// ...actions,
|
||||||
|
// [name]: {
|
||||||
|
// active,
|
||||||
|
// attrs,
|
||||||
|
// command,
|
||||||
|
// },
|
||||||
|
// }), {})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nodes,
|
nodes,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { lift, selectParentNode } from 'prosemirror-commands'
|
import { lift, selectParentNode } from 'prosemirror-commands'
|
||||||
import { undo, redo } from 'prosemirror-history'
|
import { undo, redo } from 'prosemirror-history'
|
||||||
import { undoInputRule } from 'prosemirror-inputrules'
|
import { undoInputRule } from 'prosemirror-inputrules'
|
||||||
import { isMac } from 'tiptap/utils'
|
import { isMac } from '../utils'
|
||||||
|
|
||||||
const keymap = {
|
const keymap = {
|
||||||
'Mod-z': undo,
|
'Mod-z': undo,
|
||||||
|
@ -1,24 +1,165 @@
|
|||||||
import ora from 'ora'
|
const fs = require('fs')
|
||||||
import webpack from 'webpack'
|
const path = require('path')
|
||||||
import config from './webpack.package.config'
|
const zlib = require('zlib')
|
||||||
|
const uglify = require('uglify-js')
|
||||||
|
const rollup = require('rollup')
|
||||||
|
// const configs = require('./configs')
|
||||||
|
|
||||||
const spinner = ora('Building …')
|
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')
|
||||||
|
|
||||||
export default new Promise((resolve, reject) => {
|
const vue = require('rollup-plugin-vue')
|
||||||
spinner.start()
|
const babel = require('rollup-plugin-babel')
|
||||||
|
|
||||||
webpack(config, (error, stats) => {
|
// const resolveee = require('rollup-plugin-node-resolve')
|
||||||
if (error) {
|
|
||||||
return reject(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stats.hasErrors()) {
|
// console.log('looool', VuePlugin)
|
||||||
process.stdout.write(stats.toString() + "\n");
|
|
||||||
return reject(new Error('Build failed with errors.'))
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve('Build complete.')
|
const version = require('../package.json').version
|
||||||
})
|
const banner =
|
||||||
})
|
`/*!
|
||||||
.then(success => spinner.succeed(success))
|
* tiptap v${version}
|
||||||
.catch(error => spinner.fail(error))
|
* (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)
|
||||||
|
24
webpack/build.package.old.js
Normal file
24
webpack/build.package.old.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import ora from 'ora'
|
||||||
|
import webpack from 'webpack'
|
||||||
|
import config from './webpack.package.config'
|
||||||
|
|
||||||
|
const spinner = ora('Building …')
|
||||||
|
|
||||||
|
export default new Promise((resolve, reject) => {
|
||||||
|
spinner.start()
|
||||||
|
|
||||||
|
webpack(config, (error, stats) => {
|
||||||
|
if (error) {
|
||||||
|
return reject(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stats.hasErrors()) {
|
||||||
|
process.stdout.write(stats.toString() + "\n");
|
||||||
|
return reject(new Error('Build failed with errors.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolve('Build complete.')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(success => spinner.succeed(success))
|
||||||
|
.catch(error => spinner.fail(error))
|
Loading…
Reference in New Issue
Block a user