GithubHelp home page GithubHelp logo

fis3-parser-vue-component's Introduction

fis3-parser-vue-component

由于本插件维护者开始使用webpack,本插件不再积极维护,建议使用fis的同学fork一份发布一个新插件。

如果你已经在积极维护一个新的插件并且希望使用此插件的人转过去,请提一个issue,我在这里加上一个提示。

相关

vue + vuex + vue-router + webpack 快速开始脚手架.

注意

  • 5.5.0 for [email protected]

  • 版本: >=4.10.0 <5.0.0对应[email protected], 版本>= 5.1.0对应[email protected]

  • css依赖:css的依赖应该写在js中(如:require('xxx.css')), js中依赖的css优先于style标签。

  • FIS3 构建过程分为单文件编译打包过程fis.match('component/**.vue:js')这种配置属于片段编译,对应于单文件编译阶段,配置release等属性无效。打包过程的属性和插件应该针对fis.match('component/**.vue')fis.match('component/**.css')配置。(具体见后面使用方法)

使用方法

  • 安装
npm install fis3-parser-vue-component --save-dev
  • 基础配置
fis.match('src/**.vue', {
  isMod: true,
  rExt: 'js',
  useSameNameRequire: true,
  parser: [
    fis.plugin('vue-component', {
      // [email protected] runtimeOnly
      runtimeOnly: true,          // [email protected] 有runtimeOnly模式,为true时,template会在构建时转为render方法

      // styleNameJoin
      styleNameJoin: '',          // 样式文件命名连接符 `component-xx-a.css`

      extractCSS: true,           // 是否将css生成新的文件, 如果为false, 则会内联到js中

      // css scoped
      cssScopedIdPrefix: '_v-',   // hash前缀:_v-23j232jj
      cssScopedHashType: 'sum',   // hash生成模式,num:使用`hash-sum`, md5: 使用`fis.util.md5`
      cssScopedHashLength: 8,     // hash 长度,cssScopedHashType为md5时有效

      cssScopedFlag: '__vuec__',  // 兼容旧的ccs scoped模式而存在,此例子会将组件中所有的`__vuec__`替换为 `scoped id`,不需要设为空
    })
  ],
});
  • ES2015, coffee 等
// vue组件中ES2015处理
fis.match('src/**.vue:js', {
  isMod: true,
  rExt: 'js',
  useSameNameRequire: true,
  parser: [
    fis.plugin('babel-6.x', {
      presets: ['es2015-loose', 'react', 'stage-3']
    }),
    fis.plugin('translate-es3ify', null, 'append')
  ]
});

// vue组件中coffee片段处理。
fis.match('src/**.vue:coffee', {
  parser: [
    fis.plugin('cooffe')
  ]
})
  • LESS, SASS 等
fis.match('src/**.vue:less', {
  rExt: 'css',
  parser: [fis.plugin('less-2.x')],
  postprocessor: fis.plugin('autoprefixer')
});

fis.match('src/{**.vue:scss}', {
  rExt: 'css',
  parser: [
    fis.plugin('node-sass', {
      sourceMap: true
    })
  ],
  postprocessor: fis.plugin('autoprefixer'),
});
  • Jade 等
fis.match('src/**.vue:jade', {
  parser: [
    fis.plugin('jade', {
      //
    })
  ]
})
  • 产出,打包
fis.match('src/(**).vue', {
  release: 'static/vue/$1.js'
});

fis.match('src/(component/**.css)', {
  packTo: 'component-all.css',
  release: 'static/$1'
});

原理

参考vue-loader源码,结合fis3的编译特性而编写,下面是parser阶段的主要过程:

  1. 解析vue文件,找到其中的style,template,script标签。

  2. 每一个style标签创建一个对应的虚拟文件,后缀为lang属性指定,默认css,你可以指定less或其它的后缀。对创建虚拟文件,一样会进行fis3的编译流程(属性lang的值决定该文件怎么编译),并加入当前文件的依赖。

  3. template标签的内容为Vue组件的模板,template标签同样有lang属性,默认html,会进行html特性处理,模板的内容最终会输出到module.exports.template中。

  4. script标签为文件最后输出的内容(加入模板字符串),支持lang属性。

组件编写规范

style标签可以有多个,templatescript标签只能有一个,具体请参考vue 单文件组件

css scoped支持

为了保证每一个组件样式的独立性,是当前组件定义的样式只在当前的组件内生效,引入css scoped机制。

  • 在style标签中使用scoped标志。

    <style scoped></style>
    <style lang="scss" scoped></style>
  • scoped标志会根据文件路径生成唯一的hash字符串(如:_v-23j232jj

测试demo

test 对应vue1, test2对应vue2

npm install

cd test, 编写代码…

npm install

fis3 release

fis3 server start

Vue2 JSX支持:

使用vue 官方 babel插件babel-plugin-transform-vue-jsx.

vue文件:

<script lang="jsx">
export default {
  render (h) {
    return (
      <div
        // normal attributes or component props.
        id="foo"
        // DOM properties are prefixed with domProps-
        domProps-innerHTML="bar"
        // event listeners are prefixed with on- or nativeOn-
        on-click={this.clickHandler}
        nativeOn-click={this.nativeClickHandler}
        // other special top-level properties
        class={{ foo: true, bar: false }}
        style={{ color: 'red', fontSize: '14px' }}
        key="key"
        ref="ref"
        slot="slot">
      </div>
    )
  }
}
</script>

安装babel插件:

npm install\
  babel-plugin-syntax-jsx\
  babel-plugin-transform-vue-jsx\
  babel-helper-vue-jsx-merge-props\
  --save-dev

fis相关配置

// vue组件中jsx片段处理。
fis.match('src/**.vue:jsx', {
  parser: [
    fis.plugin('babel-6.x', {
      presets: ['es2015-loose', 'stage-3'],
      plugins: ["transform-vue-jsx"]
    }),
    //fis.plugin('translate-es3ify', null, 'append')
  ]
})

fis3-parser-vue-component's People

Contributors

2betop avatar atian25 avatar biluochun avatar ccqgithub avatar ksky521 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fis3-parser-vue-component's Issues

<style>内的样式应在引入的依赖样式之后

<script>
  import Header from 'vux/src/components/x-header'
</script>
<style lang='scss'>
  .vux-header .vux-header-title, .vux-header h1{
    overflow: visible !important;
  }
</style>

编译后,<style>内的样式,在import进来模板依赖的样式之前,导致业务模板不能覆写组件样式

2.0以上编译vue-router的异步组件有问题

比如

const foo = resolve => require(['components/foo.vue'], resolve)

控制台报错

[Vue warn]: Failed to mount component: template or render function not defined.
(found in - use the "name" option for better debugging messages.)

fis.plugin('node-sass') sourceMap 无效

配置

fis.match('*.{scss,vue:scss}', {
    parser: fis.plugin('node-sass', {
        sourceMap: DEBUG,
    }),
    rExt: 'css',
})

普通scss文件有map生成,vue内的scss无map生成。
是否有什么需要注意的。

插件依赖的deasync不支持node8.0版本,导致插件无法在node8正常运行。

[ERROR] Could not locate the bindings file. Tried:
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\build\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\build\Debug\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\build\Release\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\out\Debug\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\Debug\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\out\Release\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\Release\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\build\default\deasync.node
→ F:\fis3-typescript-vue-hackernews-2.0-master\node_modules\deasync\compiled\8.9.2\win32\x64\deasync.node

入口文件没有进行render函数编译

发现新版本对于.vue文件里面的template进行了render函数的转换,并没有对入口文件处的new Vue({ template: '<App/>' })的template字段进行render函数的替换,导致vue报错
image

5.0.0版本并不支持vue 1.0渲染问题

如果vue安装到node_modules会出现以下错误

 [ERROR]

Vue packages version mismatch:

- [email protected]
- [email protected]

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

找了一下发现是vue-template-compiler会检测vue版本,用回v3.0.1就不存在这问题了,建议在文档提一下这个问题。

vue 单文件中style, lang=less 引用重复的资源,输出的css文件有冗余

我一个header, 一个footer, 都import了 variable.less.

生成的都有重复的定义变量那部分的css。

另外,产出顺序的问题。

vue组件生成的link的css,在html之前。

eg.

index.html

<link rel="stylesheet" href="./index.less">
<ent-header></ent-header>
<ent-footer></ent-footer>

output: index.html source code

<link rel="stylesheet" type="text/css" href="/src/common/header-vue-style-0.css" />
<link rel="stylesheet" type="text/css" href="/src/common/footer-vue-style-0.css" />
<link rel="stylesheet" href="/src/index.css" />

/src/common/header-vue-style-0.scss

jade is ok, 3ks ccqgithub.

It's new issue:
file: header.vue

<style lang="scss"> @import '../assets/css/base.scss'; </style>

fis-conf.js :
fis.match('*.scss', {
rExt: '.css',
useSprite: true,
postprocessor: fis.plugin('autoprefixer'),
parser: fis.plugin('node-sass')
});

error log:
Can't find /src/common/header-vue-style-0.scss
at Object.opts.importer (/usr/local/lib/node_modules/fis3-parser-node-sass/index.js:153:19)

在微信中,数据不响应,也没有报错,在其他浏览器下功能正常,

<template>
    <div>
         <p v-show="visible">测试</p>
         <p @click="close">关闭</p>
    </div>
</template>
<script>
export default {
    data() {
        return {
            visible: true
        }
    },
    methods: {
        close() {
            this.visible = false
        }
    }
}
</script>

这段代码,在chrome、或者系统自带的魅族浏览器都是正常的,但是在微信webview中,视图可以正常加载,事件也可以正常执行,但是好像this.visible=false没有作用,怎么点击,p标签都不会隐藏。

script内export的代码没有执行

源文件:

<template>
    <div>login</div>
    <button @click="ddd">ddd</button>
</template>

<script>
    export default {
        props: {
        login: {
          type: String,
          default: 'login'
        }
      },
      methods: {
            ddd() {
                alert()
            }
      }
    }
</script>

<style>
.test{
    color: red;
}
</style>

配置文件:

fis.match('/components/**.vue', {
  isMod: true,
  rExt: 'js',
  useSameNameRequire: true,
  parser: [
    fis.plugin('vue-component', {
        // 暂时还没有自定义配置哦
    }),
   fis.plugin('babel')
  ]
});

在mac上运行会报 [ERROR] content.replace is not a function

mac上有这个问题,windows上没问题,mac上只要

fis.match('/components/**.vue', {
  isMod: true,
  rExt: 'js',
  useSameNameRequire: true,
  parser: fis.plugin('vue-component', {
    cssScopeFlag: 'vuec'
  })
});

这样配置就会报错,注释掉 isMod: true ,就不报错了,是什么原因呢?

2.5.2版本的vue 无法编译

Vue packages version mismatch:

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

npm包和最新版本代码不一致?

如果把test2里的fis-config.js里的

var parserVuePlugin = require('../index');

改为:

var parserVuePlugin = require('fis3-parser-vue-component');;

fis3 release时就会报错

这个问题是我用的时候,.vue里的js代码中的export default不能用,貌似没被babel转换?我的fis3配置是:

fis.match('/src/**.vue', {
    isMod: true,
    rExt: 'js',
    parser: [
        fis.plugin('vue-component', {
          runtimeOnly: true
        })
    ]
});

fis.match('/src/**.vue:js', {
    isMod: true,
    rExt: 'js',
    parser: [
      fis.plugin('babel-6.x', {
        presets: ['es2015-loose', 'stage-3']
      })
    ],
});

莫非是我配置有问题?

cssScopedIdPrefix不唯一

比如:
现有 a.vue(__vuec__4) b.vue(__vuec__5)
重启FIS3(这个功能每个人都需要,比如第二天使用FIS) 修改a.vue一开始ID是__vuec__1多修改几次后跟b重复了。
其实就是--clear后ID值重新计算,这对文件版本控制不利。
可能hash还是最优的。

当我尝试往tr里使用插槽slot插入td时候 这部分无法渲染。

我的td写在另一个 组件内
比如
有一个table组件叫my-table
这个组件有默认插槽slot如下代码。

 <thead>
        <tr>
            <slot></slot>
        </tr>
    </thead>

当我写

<my-table>
<my-td></my-td>
</my-table>

整个table 无法渲染
去掉插槽正确
当我吧上面的slot放到td里 可以正常工作
如下

<thead>
        <tr>
          <td>
            <slot></slot>
         </td>
        </tr>
    </thead>

补充一下,在webpack里ok

[ERROR] parser.0: parser.babel-6.x: Couldn't find preset "stage-3" relative to directory

直接git clone这个仓库的报错 请问下是哪里出问题了么?

win7
fis3 3.3.29
node 4.4.4
其他都是npm install

[ERROR] parser.0: parser.babel-6.x: Couldn't find preset "stage-3" relative to directory "F:/fis3-parser-vue-component/test/src/component" [F:/fis3-parser-vue- component/test/src/component/a.vue] [F:/fis3-parser-vue-component/test/src/compo nent/a.vue]

运行的时候,老的代码报错了,怎么样做兼容

fis3 release 运行错误提示: [ERROR] parser.translate-es3ify: Parse Error: Line 5818: Invalid regular expression [F:/web/h5v3.0-demo/src/lib/vue2.0/vue.js] in [/js/house/house-list.js]

house-list.js代码:__inline('/lib/vue2.0/vue.js');

vue组件里的es6代码片段没有被编译成es5

您好,用了您的插件,vue文件组件里的做编译产出后template模板做了处理,但是产出的<script>里面的es6代码没有被编译成es5可能是什么原因,fis3也没报错!
比如在<script>标签里这么写

 let typeMap = {
    success: 'circle-check',
    info: 'information',
    warning: 'warning',
    error: 'circle-cross'
  };

在 *.vue 文件中使用 render 函数无效

看了下源码(npm 包),原来在没有template的情况下,会直接用一个默认的空函数覆盖 render,可以加一个条件判断,如果有 render 则取render

scriptStr += '\nif(module && module.exports){ module.exports.render=module.exports.default && module.exports.default.render || renderFun; module.exports.staticRenderFns=staticRenderFns;}\n';
scriptStr += '\nif(exports && exports.default){ exports.default.render=exports.default.render || renderFun; exports.default.staticRenderFns=staticRenderFns;}\n';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.