webpack-dev-server

Webpack: silence output

对着背影说爱祢 提交于 2019-11-28 16:23:03
问题 I would like to know if there's a configuration option to tell webpack to only log the "important information" to the terminal. Pretty much just errors and warnings, not all of this: There's just so much output! Would love to suppress the common stuff and only have webpack output the warnings/errors. Would like a solution for webpack , webpack-dev-server , and karma-webpack . Note : I tried noInfo: true and quiet: true but that didn't seem to do the trick. Edit: I'm thinking this may not be

webpack

徘徊边缘 提交于 2019-11-28 15:57:52
什么是?     wabpack是当前最流行的打包工具 webpack能做什么?     将 sass/less 等预编译css语言 转化为 浏览器能够认识的css文件     将多个文件打包生成为一个文件     搭建开发环境(开启了服务器)     监视文件变化,文件改变后,能够自动刷新浏览器     对于vue来说,可以将单文件组件(*.vue)类型的文件,  转化为浏览器能够识别的内容        项目打包上线: 基于vue脚手架只需要执行一条命令:npm run build 就可以对项目进行打包处理了            所有文件(css/js/html)的压缩合并             在打包的过程中,分离 或者 合并 文件             能够通过 代码分离功能实现 项目的按需加载(用到什么模块加载什么模块,懒加载)                 命令行使用方式(了解即可) // webpack 的使用步骤: // 初始化一个package.json文件 : npm init -y // 1 安装: npm i -D webpack webpack-cli // 2 webpack 使用的两种方式: // 2.1 命令行的使用方式(知道) // 2.2 配置文件 // webpack的四个核心概念: // 1 入口 entry // 2 出口

How to watch index.html using webpack-dev-server and html-webpack-plugin

纵饮孤独 提交于 2019-11-28 15:47:30
I am using webpack-dev-server for development with html-webpack-plugin to generated the index.html with revision sources. The thing is every time I change the index.html the bundle system will not rebuild again. I know the index is not in the entry, but is there a way to solve this? The problem is that index.html is not being watched by Webpack. It only watches those files that are "required" or "imported" somewhere in your code and the loaders are testing for. The solution has two parts. First require the index.html file in your entry point. Technically, you can require it anywhere in your

实现webpack的实时打包构建

▼魔方 西西 提交于 2019-11-28 15:25:20
1. 由于每次重新修改代码之后,都需要手动运行webpack打包的命令,比较麻烦,所以使用`webpack-dev-server`来实现代码实时打包编译,当修改代码之后,会自动进行打包构建。 2. 运行`cnpm i webpack-dev-server --save-dev`安装到开发依赖 3. 安装完成之后,在命令行直接运行`webpack-dev-server`来进行打包,发现报错,此时需要借助于`package.json`文件中的指令,来进行运行`webpack-dev-server`命令,在`scripts`节点下新增`"dev": "webpack-dev-server"`指令,发现可以进行实时打包,但是dist目录下并没有生成`bundle.js`文件,这是因为`webpack-dev-server`将打包好的文件放在了内存中 + 把`bundle.js`放在内存中的好处是:由于需要实时打包编译,所以放在内存中速度会非常快 + 这个时候访问webpack-dev-server启动的`http://localhost:8080/`网站,发现是一个文件夹的面板,需要点击到src目录下,才能打开我们的index首页,此时引用不到bundle.js文件,需要修改index.html中script的src属性为:`<script src="../bundle.js"><

Running a node express server using webpack-dev-server

旧街凉风 提交于 2019-11-28 15:22:57
I'm using webpack to run my react frontend successfully using the following config: { name: 'client', entry: './scripts/main.js', output: { path: __dirname, filename: 'bundle.js' }, module: { loaders: [ { test: /.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, query:{ presets: ['es2015', 'react', 'stage-2'] } } ] } } I'm trying to put up a node.js express backend as well, and would like to run that through webpack as well, so that I have a single server running both the backend and frontend, and because I want to use babel to transpile my javascript. I made a quick testserver looking

webpack/前端工程化

左心房为你撑大大i 提交于 2019-11-28 13:26:23
1.模块化的分类 A.浏览器端的模块化 ​ 1).AMD(Asynchronous Module Definition,异步模块定义) ​ 代表产品为:Require.js ​ 2).CMD(Common Module Definition,通用模块定义) ​ 代表产品为:Sea.js B.服务器端的模块化 ​ 服务器端的模块化规范是使用CommonJS规范: ​ 1).使用require引入其他模块或者包 ​ 2).使用exports或者module.exports导出模块成员 ​ 3).一个文件就是一个模块,都拥有独立的作用域 C.ES6模块化 ​ ES6模块化规范中定义: ​ 1).每一个js文件都是独立的模块 ​ 2).导入模块成员使用import关键字 ​ 3).暴露模块成员使用export关键字 小结:推荐使用ES6模块化,因为AMD,CMD局限使用与浏览器端,而CommonJS在服务器端使用。 ​ ES6模块化是浏览器端和服务器端通用的规范. 2.在NodeJS中安装babel A.安装babel ​ 打开终端,输入命令: npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/node ​ 安装完毕之后,再次输入命令安装: npm install --save @babel

Module not found: Error: Cannot resolve module 'fs'

守給你的承諾、 提交于 2019-11-28 11:50:37
I'm making a react app using Babel and Webpack and I want to use the file-exists package from npm. I already installed and saved the package as a dependency for my project. After running npm start I get this error: ERROR in ./~/file-exists/index.js Module not found: Error: Cannot resolve module 'fs' in C:\GitHub\CryptoPrices\node_modules\file-exists @ ./~/file-exists/index.js 3:9-22 file-exists uses fs as a dependency but for some reason it is not working. Npm starts and runs without any issues if I don't require file-exists anywhere. here is my webpack config file: module.exports = { entry: [

Webpack - background images not loading

▼魔方 西西 提交于 2019-11-28 08:59:00
I'm fairly new to webpack but having some problems with css-loader or file-loader. I'm trying to load a background-image but it doesn't work quite right. The background-image isn't shown, even though the devtools show the background-image style. If I copy the background-image style to the element.style block, everything works fine. Am I making a stupid mistake somewhere? The body tag should have a background image. The style appears in the developer tools and there are no errors: I can load the file 5a09e4424f2ccffb6a33915700f5cb12.jpg , but the body has no background. If I manually copy and

Nested React router 4 routes not working on Webpack 3

白昼怎懂夜的黑 提交于 2019-11-28 08:23:01
问题 As the tittle suggest i can't get routes like <Route path="/events/:id" component={EventDetailRoute} /> to work, and as i've read seems to be that the bundle in the index.html must be absolute, however i'm using the HtmlWebpackPlugin so the bundle gets injected as a relative path. I've tried to set my output config for webpack as follows: output: { path: path.resolve('dist'), filename: 'index_bundle.js', publicPath: '/' }, But that doesn't work neither. If i try this route: http://localhost

nested url routing using react-router and webpack dev server

泪湿孤枕 提交于 2019-11-28 07:27:28
问题 I'm having some issues working with react-router and webpack-dev-server to achieve nested url routing. webpack.config.js output: { path: path.resolve(__dirname, 'build'), publicPath: "/", <-- this enabled routing to /register/step2 filename: "js/bundle.js", }, routes.js const routes = { childRoutes: [ { path: '/', component: Home }, { path: '/login', component: Login }, { path: '/register', component: Register }, { path: '/register/step2', component: SecondStep }, ] }; export default (<Router