-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.plugin.js
53 lines (49 loc) · 1.55 KB
/
webpack.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const nodeExternals=require("webpack-node-externals")
module.exports=base=>{
return "input-docx,input-json,variant".split(",")
.map(a=>`we-edit-${a}`)
.map(a=>({
...base,
entry:`./packages/${a}/src/plugin.js`,
output:{
filename:`index.js`,
path:`${__dirname}/packages/${a}`,
libraryTarget:"commonjs2"//important
},
plugins:[
...base.plugins,
new LocalReference()
].filter(a=>a),
devtool:"none",//"inline-source-map",
externals:[nodeExternals({})]
/*
"react,react-dom,material-ui,prop-types,we-edit,react-redux,recompose,stream, readable-stream, we-edit-office, we-edit-representation-pagination"
.split(",")
.reduce((cols,a)=>{
a=a.trim()
cols[a]="commonjs2 "+a
return cols
},{})
*/
}))
}
class LocalReference{
apply(compiler){
compiler.hooks.emit.tap("localize we-edit-", compilation=>{
let fileName=compilation.options.output.filename
let asset=compilation.assets[fileName]
let content=asset.source()
let revised=content.replace(/require\("we-edit-/g,'require("we-edit/')
if(content!=revised){
compilation.assets[fileName]={
source(){
return revised
},
size(){
return revised.length
}
}
}
})
}
}