Webpack

React webpack error Runtime loading of image

故事扮演 提交于 2021-01-29 22:49:15
问题 I'm trying to load image at runtime in my react component. The images are stored inside src/assets folder var bg=require('../../../assets/plot1.jpg'); return( <div style ={ { backgroundImage: "url("+bg+")"} }> </div> ); This code works and loads the image. however I want to get the image path at runtime. so if i change my code as below var bg=require(props.bgImg); where the value of props.bgImg is ../../../assets/plot1.jpg . Then i get below error Error Error: Cannot find module '../../..

React webpack error Runtime loading of image

旧巷老猫 提交于 2021-01-29 22:38:49
问题 I'm trying to load image at runtime in my react component. The images are stored inside src/assets folder var bg=require('../../../assets/plot1.jpg'); return( <div style ={ { backgroundImage: "url("+bg+")"} }> </div> ); This code works and loads the image. however I want to get the image path at runtime. so if i change my code as below var bg=require(props.bgImg); where the value of props.bgImg is ../../../assets/plot1.jpg . Then i get below error Error Error: Cannot find module '../../..

Angular 11 - only build ES2015 files (no ES5)

本小妞迷上赌 提交于 2021-01-29 22:25:43
问题 Our company is using Angular 11 for one of our webapps. We tried to use the newer Webpack 5, but could not get the builds to work. What we are trying to achieve, is to remove ES5 build files, since we no longer support IE11 users. We already changed the browserslist file, but ES5 files are still being build. Is there a general solution to stop ES5 files from being build in Angular 11? 回答1: I went through the list of supported browsers, building each time a browser was added and with the

How can I render emoji in my React app (using Webpack)?

£可爱£侵袭症+ 提交于 2021-01-29 20:52:40
问题 I've tried using emojis in my React components in a few different ways (i.e. ✨, {'\u2728'}, and a few component libraries). Every way works with my dev build of the code and fails with my prod build of the same code. The prod build outputs the Unicode value of the emoji despite the method I use in the code, so I think it has something to do with my Webpack config, but I cannot find any solution on the web. Dev output Prod output 回答1: While making sure I had all the details to ask my question,

Setting up webpack to export to set folder

时光总嘲笑我的痴心妄想 提交于 2021-01-29 17:44:45
问题 I'm working on an old project still running jquery for frontend, java spring for the backend, and maven for building. I've been asked by my boss to introduce react into the stack so we can toy around with converting some of the pages. My goal is to not impact the existing implementation to heavily and instead output the result of webpack into a defined directory. This way I can just point the backend at that location for pathing. So far I have an apps folder in my workspace that contains all

How to configure webpack to automatically detect changes in .css file, and also export internal bundle.js function

杀马特。学长 韩版系。学妹 提交于 2021-01-29 17:20:38
问题 I use webpack to transpile the code. I have the following requirements: requirement1 - webpack needs to detect changes in the .css, .js files (without importing the .css file from the .js file) and automatically rebuild requirement2 - An outer .html file should call an internal bundle.js function I can achieve each of the requirements separately but not together. What should to achieve these requirements at the same time? Thanks Setting for requirement1: To achieve requirement1 I followed the

ISO proper way to chain Webpack via vue.config.js to add global .scss imports to my .vue files (vue-cli-plugin-nativescript-vue)

扶醉桌前 提交于 2021-01-29 16:15:28
问题 I have Vue.js project I've setup previously that dynamically adds defined .scss files to my .vue template files, so I can access my variables, mixins, etc. in the templates without @importing them, or having them duplicate code from imports. My problem is I'm setting up a NativeScript/Vue.js project with vue-cli-plugin-nativescript-vue and was curious if anyone has successfully setup their webpack to allow the same functionality. It's my understanding that the plugin replaces webpack with the

Is it possible to compile to commonjs from es6 with webpack

最后都变了- 提交于 2021-01-29 16:11:00
问题 The question is as the title suggests- if you have written your source code as es6 modules ( import ... from ... ) can you then compile this source back to node.js style commonjs modules ( const ... = require(...) ) using Webpack? 回答1: You sure can. Here is my webkack.config.js which is doing exactly as you ask for a legacy project that we maintain: var path = require("path"); var webpack = require('webpack'); var HardSourceWebpackPlugin = require("hard-source-webpack-plugin"); module.exports

Is the entirety of PrimeNG imported when you use it, or is it tree shaken? How can I determine it by myself?

删除回忆录丶 提交于 2021-01-29 15:58:58
问题 I am looking at optimizing a work Angular project and we're currently looking at how we are using PrimeNG. The Tree Shaking section on Webpack's documentation (https://webpack.js.org/guides/tree-shaking/) says that it relies on the ES2015 module format to determine what code can be pruned away, since CommonJS cannot be statically analyzed. So, I assume that the Angular compiler has the same limitation since it uses Webpack on the build process. That being said, I was looking at PrimeNG's

Unexpected token: name (DocumentAttributes) with webpack and UglifyJs

荒凉一梦 提交于 2021-01-29 15:49:25
问题 I am using docx 5.0.2 version for generating word document with images from the angular type script code. using webpack.optimize.UglifyJsPlugin. Getting this error when building the code . Unexpected token: name (DocumentAttributes) with webpack and UglifyJs. I assume Uglify is not able to minimize or beautify code related to docx library. Any suggestions from people using the docx package. Build used to work fine before docx package added to the package.json 回答1: The problem here is with