Browse Source

make standalone build usable in Node.js too

dev
Evan You 8 years ago
parent
commit
a4fcdbe673
  1. 14
      build/config.js
  2. 18
      src/compiler/parser/entity-decoder.js
  3. 2
      src/compiler/parser/index.js

14
build/config.js

@ -12,8 +12,6 @@ const banner =
' * Released under the MIT License.\n' + ' * Released under the MIT License.\n' +
' */' ' */'
const baseAlias = require('./alias')
const builds = { const builds = {
// Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
'web-runtime-dev': { 'web-runtime-dev': {
@ -43,10 +41,7 @@ const builds = {
dest: path.resolve(__dirname, '../dist/vue.js'), dest: path.resolve(__dirname, '../dist/vue.js'),
format: 'umd', format: 'umd',
env: 'development', env: 'development',
banner, banner
alias: {
he: './entity-decoder'
}
}, },
// Runtime+compiler standalone production build. // Runtime+compiler standalone production build.
'web-standalone-prod': { 'web-standalone-prod': {
@ -54,10 +49,7 @@ const builds = {
dest: path.resolve(__dirname, '../dist/vue.min.js'), dest: path.resolve(__dirname, '../dist/vue.min.js'),
format: 'umd', format: 'umd',
env: 'production', env: 'production',
banner, banner
alias: {
he: './entity-decoder'
}
}, },
// Web compiler (CommonJS). // Web compiler (CommonJS).
'web-compiler': { 'web-compiler': {
@ -86,7 +78,7 @@ function genConfig (opts) {
plugins: [ plugins: [
flow(), flow(),
buble(), buble(),
alias(Object.assign({}, baseAlias, opts.alias)) alias(require('./alias'))
] ]
} }

18
src/compiler/parser/entity-decoder.js

@ -1,8 +1,18 @@
/* @flow */ /* @flow */
const decoder = document.createElement('div') import { inBrowser } from 'core/util/env'
export function decode (html: string): string { let decode
decoder.innerHTML = html
return decoder.textContent /* istanbul ignore else */
if (inBrowser) {
const decoder = document.createElement('div')
decode = (html: string): string => {
decoder.innerHTML = html
return decoder.textContent
}
} else {
decode = require('he').decode
} }
export { decode }

2
src/compiler/parser/index.js

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import { decode } from 'he' import { decode } from './entity-decoder'
import { parseHTML } from './html-parser' import { parseHTML } from './html-parser'
import { parseText } from './text-parser' import { parseText } from './text-parser'
import { cached, no, camelize } from 'shared/util' import { cached, no, camelize } from 'shared/util'

Loading…
Cancel
Save