webpack-dev-server

How do you configure a Webpack dev server to serve a specific folder while running the rest of the site through a different server?

北战南征 提交于 2019-12-04 11:12:22
Some quick background: My company's site runs off a CMS with the CMS handling all routing. There are no html files, only razor files (.cshtml). While redoing the site from scratch is what I'd prefer to do, it's not an option, so I'm attempting to modernize the site slowly over time by integrating vue.js with a webpack development workflow piecemeal on a page-by-page basis. I've spent considerable time setting up webpack in a manner that allows it to process files found in the /dist/ folder only - everything else is served via http://my.server/ and handled by the CMS and backend. Through trial

webpack的总结

断了今生、忘了曾经 提交于 2019-12-04 09:33:58
Vue.js - Day5 - Webpack 在网页中会引用哪些常见的静态资源? JS .js .jsx .coffee .ts(TypeScript 类 C# 语言) CSS .css .less .sass .scss Images .jpg .png .gif .bmp .svg 字体文件(Fonts) .svg .ttf .eot .woff .woff2 模板文件 .ejs .jade .vue【这是在webpack中定义组件的方式,推荐这么用】 网页中引入的静态资源多了以后有什么问题??? 网页加载速度慢, 因为 我们要发起很多的二次请求; 要处理错综复杂的依赖关系 如何解决上述两个问题 合并、压缩、精灵图、图片的Base64编码 可以使用之前学过的requireJS、也可以使用webpack可以解决各个包之间的复杂依赖关系; 什么是webpack? webpack 是前端的一个项目构建工具,它是基于 Node.js 开发出来的一个前端工具; 如何完美实现上述的2种解决方案 使用Gulp, 是基于 task 任务的; 使用Webpack, 是基于整个项目进行构建的; 借助于webpack这个前端自动化构建工具,可以完美实现资源的合并、打包、压缩、混淆等诸多功能。 根据官网的图片介绍webpack打包的过程 webpack官网 webpack安装的两种方式 运行 npm

webpack基本使用

不问归期 提交于 2019-12-04 09:33:37
webpack安装时的坑 高版本的webpack除了全局安装webpack外,还需安装webpack-cli,在本地使用时也一样需要这样,不然会出错 webpack使用是的坑 在原始启动webpack编译时不要忘了加-o,在原始文件和要编译成为的文件目录中间 要正常使用(方便使用)就要在package.json中配置 "dev2": "webpack-dev-server --open --port 3000 --contentBase src --hot", devDependencies和dependencies的区别 -D对应devDependencies,代表打包时使用,实际上线不会使用 webpack使用 webpack使得index.html中不用引入文件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <!-- 注意: 不推荐直接在这里引用任何包和任何CSS文件 --> <!-- 因为 main

Enabling webpack hot-reload in a docker application

落爺英雄遲暮 提交于 2019-12-04 09:23:59
I have a docker app with the following containers node - source code of the project. it serves up the html page situated in the public folder. webpack - watches files in the node container and updates the public folder (from the node container) on the event of change in the code. database this is the webpack/node container setup web: container_name: web build: . env_file: .env volumes: - .:/usr/src/app - node_modules:/usr/src/app/node_modules command: npm start environment: - NODE_ENV=development ports: - "8000:8000" webpack: container_name: webpack build: ./webpack/ depends_on: - web volumes

Enable gzip compression on webpack-dev-server?

自作多情 提交于 2019-12-04 09:02:17
How do you enable gzip compression on the webpack-dev-server? It doesn't appear to be on by default. 1) Insert this line before app.use(require('webpack-dev-middleware')... : app.use(express.compress()); 2) According to source code there is undocumented option compress : $ webpack-dev-server ... --compress If you can find app.use(devMiddleware) in your project, replace it with: var compression = require('compression'); app.use(compression({})); app.use(devMiddleware); And npm install -D compression To configure it in your web pack config, use the compression module. "devServer": { compress:

使用Webpack4 搭建React项目

岁酱吖の 提交于 2019-12-04 08:38:42
使用Webpack 搭建React项目的方法和步骤 参考文章: 《How to Create a React app from scratch using Webpack 4 》 write by Linh Nguyen My 创建项目以及使用webpack编译项目 使用npm init新建功能,如果想要跳过各种询问,可以使用 -y命令: npm init -y 接下来要使用 webpack 作为开发的依赖项,以及 webpack-cli , 它可以让我们在命令行中使用webpack, 使用以下命令来安装: npm i webpack webpack-cli -D 命令解释 i:install -D: --dave-dev 以上命令等同于 npm install webpack webpack-cli --save-dev 创建一个src文件夹并在文件夹下创建index.js, 将以下示例代码写入index.js: console.log("hello"); 现在,修改package.json, 添加scripts中2条命令start 和 build,代码如下: { "name": "translation-tool-webpack-react", "version": "1.0.0", "description": "", "main": "index.js", "scripts

Cannot run webpack-dev-server inside docker

牧云@^-^@ 提交于 2019-12-04 08:25:29
问题 I have created a docker image which serves a simple react app using webpack from inside the container, but I get nothing in the browser. Here are my config files package.json { "name": "invas_client", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "webpack --inline --content-base ." }, "author": "", "license": "ISC", "dependencies": { "react": "^0.14.7", "react-dom": "^0.14.7", "react-router": "^2.0.0" }, "devDependencies": { "babel-core": "^6.5.1", "babel

Why do we need a proxy on an express.js server in order to get webpack hot reloading server functionality combined with react-routing

為{幸葍}努か 提交于 2019-12-04 07:35:26
Optional info: I'm trying to make this project built with marty.js and webpack dev server allow entry points from react-router so that it works in more than just the \ path. Thus, I'm studying THIS stack overflow answer all day long and I fail to understand the logic behind the following code and why this answer works. retozi answered: I set up a proxy to achieve this: You have a regular express webserver that serves the index.html on any > route, except if its an asset route. if it is an asset, the request gets proxied to the web-dev-server your react hot entrypoints will still point directly

How to enable Access-Control-Allow-Origin for angular 5/nodejs?

只愿长相守 提交于 2019-12-04 06:08:52
问题 Read many ways for including of 'Access-Control-Allow-Origin' and none worked for me. I use @angular/common/http module and external url as data source. by the attempt to get data instead, get error: /////................. Failed to load http://accounts.......com/accounts: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 503. account.service.ts: import { Injectable }

webpack-dev-server proxy to docker container

故事扮演 提交于 2019-12-04 04:46:44
I have 2 docker containers managed with docker-compose and can't seem to properly use webpack to proxy some request to the backend api. docker-compose.yml : version: '2' services: web: build: context: ./frontend ports: - "80:8080" volumes: - ./frontend:/16AGR/frontend:rw links: - back:back back: build: context: ./backend expose: - "8080" ports: - "8081:8080" volumes: - ./backend:/16AGR/backend:rw the service web is a simple react application served by a webpack-dev-server. the service back is a node application. I have no problem to access either app from my host : $ curl localhost > index