Skip to content

Vue模块化开发:生产环境中引入自定义js; #22

Open
@heightzhang

Description

@heightzhang
Owner

自定义js改装成对象; (引入css不需要改装)

const Util = { 自定义JS内容 }

ES6写法:

import skPlayer from '../lib/skPlayer.js';// 要导入的文件设置 =>导入
//import 'skpPlayer.css'=>当不需要使用其方法的时候

export default skPlayer //自定义js文件设置  => 导出

ES5写法

var skPlayer = require( '../lib/skPlayer.js');// 要导入的文件设置 =>导入
//require('../lib/skPlayer.js')当不需要使用其方法的时候

module.exports={  //自定义js文件设置  => 导出
  skPlayer
};

报错种类以及原因分析:
1.在webpack打包的时候,
可以在js文件中混用require和export。但是不能混用import 以及module.exports。否则报错(如下:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#')

Activity

changed the title [-]生产环境中引入自定义js;[/-] [+]模块化开发:生产环境中引入自定义js;[/+] on Jul 31, 2017
changed the title [-]模块化开发:生产环境中引入自定义js;[/-] [+]Vue模块化开发:生产环境中引入自定义js;[/+] on Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @heightzhang

        Issue actions

          Vue模块化开发:生产环境中引入自定义js; · Issue #22 · heightzhang/Three