我目前正在尝试在我的解决方案中包含一个现有的webpack包,并将所有内容输出为一个大的webpack包。
我收到了这个错误:
#Load libraries
set.seed(123)
library(tidyr)
library(ggplot2)
#Creating a fake pairwise matrix
locs <- 5
tmp <- matrix(runif(n = locs*locs),nrow = locs,ncol = locs)
tmp[upper.tri(tmp,diag = T)] <- NA
colnames(tmp) <- LETTERS[1:locs]
rownames(tmp) <- LETTERS[1:locs]
tmp
#Converting into a data frame
tmp1 <- as.data.frame(cbind(rownames(tmp),as.data.frame(tmp)))
names(tmp1)[1] <- "locA"
rownames(tmp1) <- NULL
head(tmp1)
#Changing it to long form and getting rid of NAs
tmp1 <- gather(tmp1, key = "locB",value = "value",-locA)
tmp1 <- tmp1[!is.na(tmp1$value),]
tmp1
#Making a tiled plot based on default levels
ggplot(tmp1, aes(x = locA, y=locB, fill=value, label=round(value,3)))+
geom_tile(color="black")+
geom_text(size=5,color="white")
#biological order
my.order <- c("A","C","D","B","E")
my.order
#re-leveling
tmp1$locA <- factor(tmp1$locA, levels = my.order,ordered = T)
tmp1$locB <- factor(tmp1$locB, levels = my.order,ordered = T)
tmp1
#the releveled plot
ggplot(tmp1, aes(x = locA, y=locB, fill=value, label=round(value,3)))+
geom_tile(color="black")+
geom_text(size=5,color="white")
#reordering tmp by my.order and replacing NAs with zero
x <- tmp
x<- x[my.order,my.order]
x[is.na(x)] <- 0
x
#identifying which values switch from the lower matrix to the upper matrix
y <- x
y[y !=0] <- 1
#figuring out which side of the matrix that needs to be switched to switch locA and locB
if(sum(y[lower.tri(y)]) > sum(y[upper.tri(y)])){ y[lower.tri(y)] <- 0 }
if(sum(y[lower.tri(y)]) == sum(y[upper.tri(y)])){ y[lower.tri(y)] <- 0 }
if(sum(y[lower.tri(y)]) < sum(y[upper.tri(y)])){ y[upper.tri(y)] <- 0 }
#Converting t into a long form data frame
fm <- as.data.frame(cbind(rownames(y),as.data.frame(y)))
names(fm)[1] <- "locA"
rownames(fm) <- NULL
fm <- gather(fm, key = "locB",value = "value",-locA)
#identifying which need to be switched and created an identifer to merge with
fm$action <- ifelse(fm$value == 1,"switch","keep")
fm$both <- paste0(fm$locA,fm$locB)
fm
#creating the same identifer in tmp1
tmp1$both <- paste0(tmp1$locA,tmp1$locB)
head(tmp1)
#merging the fm and tmp1 together
tmp2 <- merge(x = fm[,4:5],y = tmp1,by = "both")
tmp2
#using a for loop to make the necessary switches
i <- NULL
for(i in 1:nrow(tmp2)){
if(tmp2$action[i] == "switch"){
A <- as.character(tmp2$locA[i])
B <- as.character(tmp2$locB[i])
tmp2$locA[i] <- B
tmp2$locB[i] <- A
}
}
tmp2
#re-leveling to my order
tmp2$locA <- factor(tmp2$locA, levels = my.order,ordered = T)
tmp2$locB <- factor(tmp2$locB, levels = my.order,ordered = T)
tmp2
#now the graphic
ggplot(tmp2, aes(x = locA, y=locB, fill=value, label=round(value,3)))+
geom_tile(color="black")+
geom_text(size=5,color="white")
Webback配置:
ERROR in chunk lib [entry]
bundle.js
Conflict: Multiple assets emit to the same filename bundle.js
在线回购:https://github.com/umarmw/js-extend-module-wp
是否可以将webpack包合并到另一个?还是有更好的选择?
答案 0 :(得分:0)
我通过结合 node.js readFileSync 和 writeFileSync 以及webpack-shell-plugin <解决了上述问题/ p>
Webpack配置:
const path = require('path');
const webpack = require('webpack');
const WebpackShellPlugin = require('webpack-shell-plugin');
let inputFolderPath = "js\\";
let outputFolderPath = "dist\\tmp\\";
let bundleName = "bundle.js";
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader'
}],
}
],
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new WebpackShellPlugin({
onBuildStart:[],
onBuildEnd:['node node.bundle']
}),
],
externals: {
myScoreUILib: 'MyScoreUILib'
},
context: path.resolve(__dirname, inputFolderPath),
entry: {
app: './app.js'
},
output: {
path: path.resolve(__dirname, outputFolderPath),
filename: "app.js"
},
devtool: 'source-map'
};
和' node.bundle.js '
const fs = require('fs');
const path = require('path');
const lib = path.join(__dirname, './dist/tmp/lib.bundle.js');
const app = path.join(__dirname, './dist/tmp/app.js');
const bundle = path.join(__dirname, './dist/bundle.js');
let libContent = fs.readFileSync(lib);
let appContent = fs.readFileSync(app);
fs.writeFileSync(bundle, libContent+'\n'+appContent);
最后,我最终只是使用node.js将两个webpack包连接在一起