importwebpackfrom'webpack';importCleanPluginfrom'clean-webpack-plugin';importExtractTextPluginfrom'extract-text-webpack-plugin';importHtmlWebpackPluginfrom'html-webpack-plugin';import{contextPath,fullBundlePath,servletPath}from'./resource_paths_config';letextractStyles=newExtractTextPlugin({filename:'bundle.[md5:contenthash:hex:20].css',});letconfig={mode:'development',devtool:'source-map',context:contextPath,entry:['./resources/js/leading_edge/leading_edge_module.js'],resolve:{alias:{jquery:`${__dirname}/node_modules/jquery/dist/jquery`,vendor:`${contextPath}/resources/vendor`,$scss:`${__dirname}/src/main/webapp/resources/scss`,less:`${contextPath}/WEB-INF/less`,clipboard:`${__dirname}/node_modules/clipboard/dist/clipboard`,projectRoot:__dirname,},descriptionFiles:['package.json'],modules:['node_modules'],},output:{path:fullBundlePath,publicPath:`${servletPath}/resources/build/`,filename:'bundle.[hash].js',},module:{rules:[{test:/\.(js|jsx)$/,exclude:/node_modules/,use:[{loader:'babel-loader',options:{presets:[['@babel/preset-env',{useBuiltIns:'usage',},],'@babel/react',],plugins:['angularjs-annotate','transform-class-properties','@babel/plugin-transform-runtime','@babel/plugin-proposal-optional-chaining',],},},],},{//Load all templates into $templateCache
test:/(\.html)$/,use:[{loader:'ng-cache-loader?module=leadingEdge'}],},{test:/\.css$/,use:extractStyles.extract({use:[{loader:'css-loader',options:{sourceMap:true,},},],}),},{test:/\.scss$/,use:[{loader:'style-loader',},{loader:'css-loader',options:{modules:true,localIdentName:'[name]__[local]___[hash:base64:5]',},},{loader:'sass-loader',},],},{test:/\.less$/,use:extractStyles.extract({use:[{loader:'css-loader',options:{sourceMap:true,},},{loader:'less-loader',options:{sourceMap:true,relativeUrls:false,},},],}),},{test:/\.(woff2?|svg|ttf|eot)([?]?.*)$/,use:[{loader:'file-loader',options:{name:'fonts/[name].[hash].[ext]',},},],},{test:/\.(svg|png|gif|jpg)$/,use:[{loader:'file-loader',options:{name:'image/[name].[hash].[ext]',},},],},{test:/jquery\.js$/,use:[{loader:'expose-loader',options:'jQuery',},{loader:'expose-loader',options:'$',},],},],},plugins:[extractStyles,newwebpack.ProvidePlugin({'window.Headroom':'headroom.js/dist/headroom.js',}),newCleanPlugin([fullBundlePath,`${contextPath}/WEB-INF/generated`],{verbose:false,}),newHtmlWebpackPlugin({inject:false,filename:`${contextPath}/WEB-INF/generated/script_tag.jsp`,template:`${contextPath}/WEB-INF/ejs/script_tag.tmpl.ejs`,}),newHtmlWebpackPlugin({inject:false,filename:`${contextPath}/WEB-INF/generated/style_tag.jsp`,template:`${contextPath}/WEB-INF/ejs/style_tag.tmpl.ejs`,}),],};module.exports=config;
it was made on 3.x.x webpack and I'm trying to move it to 4 so I can update to 5, it's working with angular and react (bc migration from angular to react...)
Hey, thanks for the config files! As far I can see, you have a duplicate Babel configuration. You should not need to have the preset/plugin part of babel loader in your webpack config. Webpack when parsing through the babel-loader should get the configuration from your babelrc only. Try to just keep the test and loader part from babel-loader, and specify only your presets/plugin in the babel config.
1
u/CanardWcCitron Nov 05 '21
Babel config ?
Edit: webpack config too ?
Edit 2: for sure, it's coming from webpack not being able to bundle some badly transpiled code from Babel, so need the config to go further
1
u/CanardWcCitron Nov 06 '21
Hey, thanks for the config files! As far I can see, you have a duplicate Babel configuration. You should not need to have the preset/plugin part of babel loader in your webpack config. Webpack when parsing through the babel-loader should get the configuration from your babelrc only. Try to just keep the test and loader part from babel-loader, and specify only your presets/plugin in the babel config.
On a second though, it seems possible that you're missing some specification on the output module type (commonJS/UMD, etc..) Not sure about your specific config, but you may have a look to this : https://github.com/webpack/webpack/issues/3974#issuecomment-378229124
Good luck, and I hope you will get through this ! Webpack is a hell of a learning curve, but perseverance will pay !