|
| 1 | +constpath=require("path"); |
| 2 | +const{ VueLoaderPlugin}=require("vue-loader"); |
| 3 | +constMiniCssExtractPlugin=require("mini-css-extract-plugin"); |
| 4 | +constHtmlWebpackPlugin=require("html-webpack-plugin"); |
| 5 | +const{ ModuleFederationPlugin}=require("webpack").container; |
| 6 | +constdeps=require("./package.json").dependencies; |
| 7 | + |
| 8 | +module.exports=(env={})=>({ |
| 9 | +mode:"development", |
| 10 | +cache:false, |
| 11 | +devtool:"source-map", |
| 12 | +optimization:{ |
| 13 | +minimize:false, |
| 14 | +}, |
| 15 | +target:"web", |
| 16 | +entry:path.resolve(__dirname,"./src/bootstrap.js"), |
| 17 | +output:{ |
| 18 | +publicPath:"auto", |
| 19 | +}, |
| 20 | +resolve:{ |
| 21 | +extensions:[".vue",".jsx",".js",".json"], |
| 22 | +alias:{ |
| 23 | +vue:"vue/dist/vue.esm-bundler.js", |
| 24 | +}, |
| 25 | +}, |
| 26 | +experiments:{ |
| 27 | +topLevelAwait:true, |
| 28 | +}, |
| 29 | +module:{ |
| 30 | +rules:[ |
| 31 | +{ |
| 32 | +test:/\.jsx?$/, |
| 33 | +loader:"babel-loader", |
| 34 | +exclude:/node_modules/, |
| 35 | +options:{ |
| 36 | +presets:["@babel/preset-react"], |
| 37 | +}, |
| 38 | +}, |
| 39 | +{ |
| 40 | +test:/\.vue$/, |
| 41 | +use:"vue-loader", |
| 42 | +}, |
| 43 | +{ |
| 44 | +test:/\.png$/, |
| 45 | +use:{ |
| 46 | +loader:"url-loader", |
| 47 | +options:{limit:8192}, |
| 48 | +}, |
| 49 | +}, |
| 50 | +{ |
| 51 | +test:/\.css$/, |
| 52 | +use:[ |
| 53 | +{ |
| 54 | +loader:MiniCssExtractPlugin.loader, |
| 55 | +options:{}, |
| 56 | +}, |
| 57 | +"css-loader", |
| 58 | +], |
| 59 | +}, |
| 60 | +], |
| 61 | +}, |
| 62 | +plugins:[ |
| 63 | +newMiniCssExtractPlugin({ |
| 64 | +filename:"[name].css", |
| 65 | +}), |
| 66 | +newModuleFederationPlugin({ |
| 67 | +name:"app1", |
| 68 | +remotes:{ |
| 69 | +app2:"app2@http://localhost:3002/remoteEntry.js", |
| 70 | +}, |
| 71 | +shared:{ |
| 72 | + ...deps, |
| 73 | +react:{ |
| 74 | +singleton:true, |
| 75 | +requiredVersion:deps.react, |
| 76 | +}, |
| 77 | +"react-dom":{ |
| 78 | +singleton:true, |
| 79 | +requiredVersion:deps["react-dom"], |
| 80 | +}, |
| 81 | +}, |
| 82 | +}), |
| 83 | +newHtmlWebpackPlugin({ |
| 84 | +template:path.resolve(__dirname,"./index.html"), |
| 85 | +chunks:["main"], |
| 86 | +}), |
| 87 | +newVueLoaderPlugin(), |
| 88 | +], |
| 89 | +devServer:{ |
| 90 | +static:{ |
| 91 | +directory:path.join(__dirname), |
| 92 | +}, |
| 93 | +compress:true, |
| 94 | +port:3001, |
| 95 | +hot:true, |
| 96 | +headers:{ |
| 97 | +"Access-Control-Allow-Origin":"*", |
| 98 | +"Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS", |
| 99 | +"Access-Control-Allow-Headers": |
| 100 | +"X-Requested-With, content-type, Authorization", |
| 101 | +}, |
| 102 | +}, |
| 103 | +}); |