webpack-4

How to create multi output files?

巧了我就是萌 提交于 2020-07-10 08:44:06
问题 I would like to bundle my chrome extension with Webpack. The source consists multiple entries and the content of the webpack.config.js looks as follows: const path = require("path"); module.exports = { entry: { actions: './src/actions/index.js', options: './src/options/index.js' }, output: { filename: '[name].js', path: path.resolve(__dirname, "dist") } }; And folder structure: The actions/index.js and options/index.js files are entries. My goal is, when the src get bundled then dist folder

Webpack Lazy Loading with Typescript

北城以北 提交于 2020-07-09 11:56:06
问题 I have a problem with lazy loading and webpack. There is a video of Sean Larkin showing how easy it is with webpack 4 to create a lazy loaded bundle (Here). But when I try to do it with typescript I run into some problems. index.ts export const someThing = something => import("./lazy/lazy"); and lazy/lazy.ts export default "I am lazy"; when I run it without any webpack configuration and name the files to ".js" I get a main chunk and a small chunk for the lazy loaded module. But when I run it

Using components from an external directory in a Electron project with Webpack

时光总嘲笑我的痴心妄想 提交于 2020-06-29 03:18:52
问题 I am trying to do this as simple as possible, I studied Yarn Workspaces for a while, but that's a solution that's currently doesn't work with Electron, there were simply too many issues. I have am Electron project here: ./electron/ I have a directory with components here: ./common/ The components are developed in React/JSX, there is nothing really fancy about them. That said, I am using hooks (useXXX). I tried many ways to include those components (ideally, I wanted to use Yarn Workspaces,

CopyWebpackPlugin - ignore a folder

让人想犯罪 __ 提交于 2020-06-27 10:34:07
问题 Using CopyWebpackPlugin, I am not able to ignore a specific folder or a specific file. It copies everything. What I have done in the webpack.config.js: new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets', ignore: ['src/assets/img/folder/test.png'] }, ]), I also tried like that: new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets', ignore: ['src/assets/img/folder/*'] }, ]), Regarding the readme I think I am doing right. 回答1: Try this: ignore: ['img/folder/**/*'] This will not copy

Webpack: How to inject javascript into the HTML instead of separate JS file

安稳与你 提交于 2020-06-27 09:02:23
问题 Is there a way to have webpack inject the output into the HTML instead of a separate file? <html> <head> </head> <body> <script type="text/javascript"> // webpack puts the output here </script> </body> </html> 回答1: I had to use the html-webpack-inline-source-plugin . https://github.com/DustinJackson/html-webpack-inline-source-plugin plugins: [ new HtmlWebpackPlugin({ inlineSource: '.(js|css)$' // embed all javascript and css inline }), new HtmlWebpackInlineSourcePlugin() ] 来源: https:/

How to move css links to the bottom of the html document with webpack?

六眼飞鱼酱① 提交于 2020-05-17 07:59:29
问题 The way my webpack is currently being set up, it places the css resources links in the head of the document, which blocks the rendering of my initial content. Example: <head> <link href="main.28396255e7678a2cdf3c.css" rel="stylesheet"> </head> Therefore, I'd like to move them at the bottom of the document, right before </body> . Is there a way to configure what I already have, to achieve this, or is there maybe a plugin I wasn't able to find? Here's some of my webpack config: {{ entry: { app:

Error in Entry Module not found - in Webpack Config file

落爺英雄遲暮 提交于 2020-05-15 05:04:13
问题 I am trying to setup webpack for ReactJs. I am clueless what is wrong with my Webpack Config File which gives me ERROR in Entry module not found: Error: Can't resolve './src' in 'D:\wd\javascript\Projects\reactjs-basics CODE IS HERE - Two files "Webpack.config.js " and "Package.json" Webpack.config.js code is : var webpack = require('webpack'); var path = require('path'); var DIST_DIR = path.resolve(__dirname,'dist'); var SRC_DIR = path.resolve(__dirname,'src'); var config = { entry: SRC_DIR+

Error in Entry Module not found - in Webpack Config file

我的未来我决定 提交于 2020-05-15 05:02:20
问题 I am trying to setup webpack for ReactJs. I am clueless what is wrong with my Webpack Config File which gives me ERROR in Entry module not found: Error: Can't resolve './src' in 'D:\wd\javascript\Projects\reactjs-basics CODE IS HERE - Two files "Webpack.config.js " and "Package.json" Webpack.config.js code is : var webpack = require('webpack'); var path = require('path'); var DIST_DIR = path.resolve(__dirname,'dist'); var SRC_DIR = path.resolve(__dirname,'src'); var config = { entry: SRC_DIR+

Webpack, Babel 7.4.0 and core-js 3

£可爱£侵袭症+ 提交于 2020-05-15 03:46:24
问题 Given the following package.json { "name": "webpack-babel7", "version": "1.0.0", "main": "index.js", "license": "MIT", "devDependencies": { "@babel/core": "^7.4.4", "@babel/preset-env": "^7.4.4", "babel-loader": "^8.0.5", "webpack": "^4.30.0", "webpack-cli": "^3.3.2" }, "dependencies": { "core-js": "3" } } babel.config.js const presets = [ [ '@babel/env', { targets: { chrome: '74', }, useBuiltIns: 'usage', debug: true, corejs: 3, }, ], ] module.exports = { presets } webpack.config.js const

How to use dynamic import in typescript with webpack application

半城伤御伤魂 提交于 2020-02-12 05:30:10
问题 I have import some of my modules dynamically based on button click, i have used like below" import { Button } from '@syncfusion/ej2-buttons'; // Initialize Button component. let button: Button = new Button({ content: 'Button' }); // Render initialized Button. button.appendTo('#element'); document.getElementById('element').addEventListener("click", function(){ check(); }); async function check() { import("@syncfusion/ej2-grids").then((Grid) => { debugger console.log(Grid); }); } my webpack