surmon-china / vue-codemirror

@codemirror code editor component for @vuejs
https://github.surmon.me/vue-codemirror
MIT License
3.25k stars 380 forks source link

Uglify complains SyntaxError #1

Closed zchrissirhcz closed 7 years ago

zchrissirhcz commented 7 years ago

我把vue-codemirror在自己项目中装好后,buld阶段报错:

ERROR in static/js/vendor.8de923185c435eea8019.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [./~/.1.0.4@vue-codemirror/index.js:11,0]

有什么建议吗?

我的package.json中有配置babel相关的包:

{
  "name": "rsite",
  "version": "1.0.0",
  "description": "R浣撻獙鏁欏web鍓嶇",
  "author": "zchrissirhcz <zchrissirhcz@gmail.com>",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "build": "node build/build.js",
    "test": "",
    "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
  },
  "dependencies": {
    "babel-runtime": "^6.0.0",
    "codemirror": "^5.19.0",
    "vue": "^1.0.21",
    "vue-paginate": "^2.1.2",
    "vue-resource": "^0.9.3",
    "vue-router": "^0.7.13",
    "vuex": "^1.0.0-rc.2",
    "whatwg-fetch": "^1.0.0"
  },
  "devDependencies": {
    "babel-core": "^6.0.0",
    "babel-eslint": "^6.1.2",
    "babel-loader": "^6.0.0",
    "babel-plugin-transform-runtime": "^6.0.0",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-stage-2": "^6.0.0",
    "babel-register": "^6.0.0",
    "connect-history-api-fallback": "^1.1.0",
    "css-loader": "^0.23.0",
    "eslint": "^2.10.2",
    "eslint-config-standard": "^5.1.0",
    "eslint-friendly-formatter": "^2.0.5",
    "eslint-loader": "^1.3.0",
    "eslint-plugin-html": "^1.3.0",
    "eslint-plugin-promise": "^1.0.8",
    "eslint-plugin-standard": "^1.3.2",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.13.3",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.4",
    "function-bind": "^1.0.2",
    "html-webpack-plugin": "^2.8.1",
    "http-proxy-middleware": "^0.12.0",
    "json-loader": "^0.5.4",
    "ora": "^0.2.0",
    "shelljs": "^0.6.0",
    "url-loader": "^0.5.7",
    "vue-codemirror": "^1.0.4",
    "vue-hot-reload-api": "^1.2.0",
    "vue-html-loader": "^1.0.0",
    "vue-loader": "^8.3.0",
    "vue-style-loader": "^1.0.0",
    "webpack": "^1.12.2",
    "webpack-dev-middleware": "^1.4.0",
    "webpack-hot-middleware": "^2.6.0",
    "webpack-merge": "^0.8.3"
  }
}
zchrissirhcz commented 7 years ago

应该是es6的问题。index.js中都是es6写法,缺少对于es6的配置项。

zchrissirhcz commented 7 years ago

或者临时替换为es5的写法,当然也最好符合eslint标准:

/**
 * Vue-CodeMirror
 * @author Surmon.me
 * @date 2016-9-22
 */

'use strict'
const CodeMirror = require('codemirror/lib/codemirror.js')
require('codemirror/lib/codemirror.css')

const CmComponentBuild = function (Vue) {
  const CmComponent = Vue.extend({
    template: '<textarea></textarea>',
    data: function () {
      return {
        content: ''
      }
    },
    props: {
      code: String,
      options: {
        type: Object,
        default: function () {
          return {
            styleActiveLine: true,
            lineNumbers: true,
            mode: 'javascript',
            lineWrapping: true
          }
        }
      }
    },
    created: function () {
      this.options    = this.options || {}
      const language  = this.options.mode || 'javascript'
      const theme     = this.options.theme
      require('codemirror/mode/' + language + '/' + language + '.js')
      if (!!theme && theme !== 'default') require('codemirror/theme/' + theme + '.css')
    },
    ready: function () {
      this.editor = CodeMirror.fromTextArea(this.$el, this.options)
      this.editor.setValue(this.code || this.content)
      this.editor.on('change', function (cm) {
        this.content = cm.getValue()
        this.code = cm.getValue()
      })
    },
    watch: {
      'code': function (newVal, oldVal) {
        // console.log('update', newVal)
        // this.editor.setValue(newVal)
        // this.content = newVal
      }
    }
  })
  Vue.component('codemirror', CmComponent)
}

const codemirror = {
  install: function (Vue) {
    CmComponentBuild(Vue)
  }
}

module.exports = codemirror
surmon-china commented 7 years ago

稍后更新,感谢反馈

surmon-china commented 7 years ago

已更新

Rainboylvx commented 7 years ago

我在build过程种,还是报错了SyntaxError: Unexpected token: operator (>) [./~/.1.0.4@vue-codemirror/es6.js

我把index 中 require(es6.js) 去掉后 就可以了

surmon-china commented 7 years ago

已经修复,请更新