Przeglądaj źródła

separate builds with/without compiler

Evan You 10 lat temu
rodzic
commit
1c8afd26a9
6 zmienionych plików z 22 dodań i 8 usunięć
  1. 4 2
      build/build.js
  2. 1 0
      build/dev-entry.js
  3. 0 1
      src/index.umd.js
  4. 2 4
      src/instance/index.js
  5. 14 0
      src/with-compiler.js
  6. 1 1
      webpack.config.js

+ 4 - 2
build/build.js

@@ -34,6 +34,8 @@ var plugins = [
 // CommonJS build.
 // this is used as the "main" field in package.json
 // and used by bundlers like Webpack and Browserify.
+// doesn't come with the compiler because it's meant to be
+// used with vue-loader which pre-compiles the template.
 rollup.rollup({
   entry: 'src/index.js',
   plugins: plugins
@@ -47,7 +49,7 @@ rollup.rollup({
 // Standalone Dev Build
 .then(function () {
   return rollup.rollup({
-    entry: 'src/index.js',
+    entry: 'src/with-compiler.js',
     plugins: [
       replace({
         'process.env.NODE_ENV': "'development'"
@@ -65,7 +67,7 @@ rollup.rollup({
 .then(function () {
   // Standalone Production Build
   return rollup.rollup({
-    entry: 'src/index.js',
+    entry: 'src/with-compiler.js',
     plugins: [
       replace({
         'process.env.NODE_ENV': "'production'"

+ 1 - 0
build/dev-entry.js

@@ -0,0 +1 @@
+module.exports = require('../src/with-compiler')['default']

+ 0 - 1
src/index.umd.js

@@ -1 +0,0 @@
-module.exports = require('./index')['default']

+ 2 - 4
src/instance/index.js

@@ -1,14 +1,12 @@
-import { compile } from '../compiler/index'
 import { observe } from '../observer/index'
 import Watcher from '../observer/watcher'
 import { h, patch } from '../vdom/index'
-import { nextTick, isReserved, getOuterHTML } from '../util/index'
+import { nextTick, isReserved } from '../util/index'
 
 export default function Component (options) {
   this.$options = options
   this._data = options.data
   const el = this._el = document.querySelector(options.el)
-  const render = compile(getOuterHTML(el))
   this._el.innerHTML = ''
   Object.keys(options.data).forEach(key => proxy(this, key))
   if (options.methods) {
@@ -18,7 +16,7 @@ export default function Component (options) {
   }
   this._ob = observe(options.data)
   this._watchers = []
-  this._watcher = new Watcher(this, render, this._update)
+  this._watcher = new Watcher(this, options.render, this._update)
   this._update(this._watcher.value)
 }
 

+ 14 - 0
src/with-compiler.js

@@ -0,0 +1,14 @@
+import { compile } from './compiler/index'
+import { getOuterHTML, query } from './util/index'
+import Component from './instance/index'
+
+export default function Vue (options) {
+  if (!options.render) {
+    if (options.template) {
+      options.render = compile(options.template)
+    } else if (options.el) {
+      options.render = compile(getOuterHTML(query(options.el)))
+    }
+  }
+  return new Component(options)
+}

+ 1 - 1
webpack.config.js

@@ -1,7 +1,7 @@
 var path = require('path')
 
 module.exports = {
-  entry: path.resolve(__dirname, 'src/index.umd.js'),
+  entry: path.resolve(__dirname, 'build/dev-entry.js'),
   output: {
     path: path.resolve(__dirname, 'dist'),
     filename: 'vue.js',