Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
heightzhang opened this issue Jul 31, 2017 · 0 comments
Open

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

heightzhang opened this issue Jul 31, 2017 · 0 comments
Labels

Comments

@heightzhang
Copy link
Owner

heightzhang commented Jul 31, 2017

自定义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 '#')

@heightzhang heightzhang changed the title 生产环境中引入自定义js; 模块化开发:生产环境中引入自定义js; Jul 31, 2017
@heightzhang heightzhang added the Vue label Aug 2, 2017
@heightzhang heightzhang changed the title 模块化开发:生产环境中引入自定义js; Vue模块化开发:生产环境中引入自定义js; Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant