点击关注「百度Geek说」
更多技术干货等着你
npx @efox/emp-cli init
cd my-emp && yarn && yarn dev
之后,项目将会自动打开在浏览器。@efox/emp-cli
,可以通过全局安装 npm install -g @efox/emp-cli
或 yarn global add @efox/emp-cli
。npm uninstall -g @efox/emp-cli
or yarn global remove @efox/emp-cli
确保 npx 使用的 @efox/emp-cli
是最新版本。/**
* @type {import('@efox/emp-cli').EMPConfig}
*/
module.exports = {
webpack() {
return {
devServer: {
/**
* 设置 devServer
*/
port: 8002,
},
}
},
async moduleFederation() {
return {
/**
* name: 对外暴露项目名,
*/
name: 'demo',
/**
* filename: 对外暴露引用文件名,
*/
filename: 'emp.js',
/**
* remotes 远程模块
* remotes: {
* '引用别名': '远程模块项目名@远程模块的emp.js文件地址',
* },
*/
remotes: {
'@emp/demo1': 'demo1@http://localhost:8001/emp.js',
},
/**
* exposes 暴露模块
* exposes: {
* '对外暴露的相对路径': '当前项目相对路径',
* },
*/
exposes: {
'./components/Hello': 'src/components/Hello',
'./helper': 'src/helper',
},
/**
* shared 共享的第三方依赖
* shared: ['依赖名'],
*/
shared: ['react', 'react-dom'],
}
},
}
const withVue2 = require('@efox/emp-vue2')
module.exports = withVue2(({config}) => {
const projectName = 'vue2Project'
const port = 8008
config.output.publicPath(`http://localhost:${port}/`)
config.devServer.port(port)
config.plugin('mf').tap(args => {
args[0] = {
...args[0],
...{
/**
* name: 对外暴露项目名,
*/
name: projectName,
/**
* filename: 对外暴露引用文件名,
*/
filename: 'emp.js',
/**
* remotes 远程模块
* remotes: {
* '引用别名': '远程模块项目名@远程模块的emp.js文件地址',
* },
*/
remotes: {
'@v2b': 'vue2Base@http://localhost:8009/emp.js',
},
/**
* exposes 暴露模块
* exposes: {
* '对外暴露的相对路径': '当前项目相对路径',
* },
*/
exposes: {
'./Content': './src/components/Content',
},
/**
* shared 共享的第三方依赖
* shared: ['依赖名'],
*/
shared: ['vue/dist/vue.esm.js'],
},
}
return args
})
config.plugin('html').tap(args => {
args[0] = {
...args[0],
...{
title: 'EMP Vue2 Project',
},
}
return args
})
})
EMP 不推荐大家跨框架调用,因为这样会增加维护成本和风险。但是我们还是支持:
招聘信息
百度直播研发部招聘研发岗位,包括客户端-Android/iOS方向,服务端-Go/PHP方向。我们负责百度直播业务,对直播业务感兴趣欢迎加入我们。
简历投递邮箱:geektalk@baidu.com (投递备注【直播研发】)