webpack-dev-server 配置
webpack.config.js 配置
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var AssetsPlugin = require('assets-webpack-plugin');
var path = require("path");
var umdREquirePlugin = require("umd-require-webpack-plugin");
var MoveToParentMergingPlugin = require('move-to-parent-merging-webpack-plugin');
var hotModuleReplacementPlugin = require("webpack/lib/HotModuleReplacementPlugin");
var webpack = require("webpack");
var isDevServer = process.argv[1].indexOf('webpack-dev-server') !== -1;
var devServer = {
historyApiFallback: true,
hot: true,
inline: true,
progress: true
};
var entry = require("./entry-2");
var modulesEntry = require("./modules/entry");
for (var key in modulesEntry) {
entry[key] = modulesEntry[key];
}
var needCsshint = process.argv.indexOf('--csshint') !== -1;
var config = {
// The standard entry point and output config
entry: entry,
output: {
path: path.join(__dirname, "assets2"), //path.join(__dirname, "assets", "[hash]"),
//publicPath: "//s3-us-west-1.amazonaws.com/chime-static-cloud/site/assets/",
publicPath: "/static/new-template/",
filename: "[name].js",
chunkFilename: "bundle-[id].js"
},
/*
entry: "./entry.js",
output: {
path: __dirname,
filename: "bundle.js"
},
*/
module: {
loaders: [
// Extract css files
{
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", `css-loader${needCsshint ? '!csslint-loader' : ''}!autoprefixer-loader`)
},
// Optionally extract less files
// or any other compile-to-css language
{
test: /\.less$/,
loader: ExtractTextPlugin.extract("style-loader", `css-loader${needCsshint ? '!csslint-loader' : ''}!autoprefixer-loader!less-loader`)
}, {
test: /\.(sass|scss)/,
loader: ExtractTextPlugin.extract("style-loader", `css-loader${needCsshint ? '!csslint-loader' : ''}!autoprefixer-loader!sass-loader?outputStyle=expanded`)
},
// You could also use other loaders the same way. I. e. the autoprefixer-loader
{
test: /\.woff2$/,
loader: 'url-loader?limit=1000000&name=build/[name].[ext]'
}, {
test: /\.(png|jpg|svg|gif)$/i,
loaders :[
'url-loader?name=build/[name].[ext]',
'image-webpack'
]
}, {
test: /\.tpl\.html$/,
loader: 'html-template-loader'
}, {
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules|lib/,
query: {
presets: ['es2015', 'react']
}
}
]
},
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [
new ExtractTextPlugin("[name].css"),
new CommonsChunkPlugin({
name: "search-app.chunk",
chunks: isDevServer ? [] : ["search-app-init", "template-home", "listing-detail", "search-map"]
}),
new CommonsChunkPlugin({
name: "common-app.chunk",
//chunks: isDevServer ? [] : entryArray
chunks: isDevServer ? [] : ["app-init","listing-detail","sell","blog","sell-report","neigh","nbhd-detail","blog-detail","search-map","profile","template-home","contact","template-evaluation","evaluation-step1","evaluation-step1-new","evaluation-step2","evaluation-step2-new","evaluation-step3","template-about","template-listing-feature","template-listing-sold", "search-app.chunk"]
}),
//new CommonsChunkPlugin("search-app.chunk.js", ["search-app", "home", "listing-detail"]),
new AssetsPlugin({filename: './version-control/source-map-test-2.json', prettyPrint: true}),
new MoveToParentMergingPlugin(),
new umdREquirePlugin(),
new hotModuleReplacementPlugin(),
//new webpack.optimize.UglifyJsPlugin()
],
resolve: {
modulesDirectories: ['.', 'node_modules']
},
resolveLoader: {
modulesDirectories: ['.', 'node_modules']
},
externals:{
"jquery":"jQuery",
"react" : "React",
"react-dom" :"ReactDOM"
},
devServer: isDevServer ? devServer : "",
};
//运行`node js-exclude.js js,new-template/js "js,jsx"`会生成最新的.jsexclude文件
if(process.argv.indexOf('--jshint') !== -1){
var jshint = JSON.parse(require('fs').readFileSync('./.jshintrc').toString().replace(/\/\/[^\r\n]+/g, ''));
var jsExcludes = require('fs').readFileSync('./.jsexclude').toString().split(/\r\n|\r|\n/).map(function(item){
return path.normalize(__dirname + '/' + item);
});
config.module.preLoaders = [{
test: /.js$/,
exclude: function(file){
return jsExcludes.indexOf(file) !== -1 || /[\/\\]node_modules[\/\\]/.test(file) || !/[\/\\]site[\/\\]/.test(file)
},
loader: "jshint-loader"
}];
config.jshint = jshint;
}
//运行`node js-exclude.js css,sass,jsp/custom-style,new-template/sass "css,scss,less"`会生成最新的.cssexclude文件
if(needCsshint){
var cssExcludes = require('fs').readFileSync('./.cssexclude').toString().split(/\r\n|\r|\n/).map(function(item){
return path.normalize(__dirname + '/' + item);
});
config.csslint = {
rules: {
// 'box-model': 1,
'display-property-grouping': 1,
// 'duplicate-properties': 1,
'empty-rules': 1,
'known-properties': 1,
'ids': 1,
'multi-rules-newline': 1,
'rule-name': 1
},
exclude: function(file){
return cssExcludes.indexOf(file) !== -1 || /[\/\\]node_modules[\/\\]/.test(file) || !/[\/\\]site[\/\\]/.test(file)
},
};
}
module.exports = config;
webpack-dev-server 配置
var WebpackDevServer = require("webpack-dev-server");
var webpack = require("webpack");
var compiler = webpack({
// configuration
});
var server = new WebpackDevServer(compiler, {
// webpack-dev-server options
contentBase: "/Users/yincheng/code/homethy-static/site/",
// or: contentBase: "http://localhost/",
hot: true,
// Enable special support for Hot Module Replacement
// Page is no longer updated, but a "webpackHotUpdate" message is send to the content
// Use "webpack/hot/dev-server" as additional module in your entry point
// Note: this does _not_ add the `HotModuleReplacementPlugin` like the CLI option does.
/ Set this as true if you want to access dev server from arbitrary url.
// This is handy if you are using a html5 router.
historyApiFallback: false,
// Set this if you want to enable gzip compression for assets
compress: true,
// Set this if you want webpack-dev-server to delegate a single path to an arbitrary server.
// Use "*" to proxy all paths to the specified server.
// This is useful if you want to get rid of 'http://localhost:8080/' in script[src],
// and has many other use cases (see https://github.com/webpack/webpack-dev-server/pull/127 ).
/*
proxy: {
"*": "http://localhost:9090"
},
*/
// pass [static options](http://expressjs.com/en/4x/api.html#express.static) to inner express server
staticOptions: {
},
// webpack-dev-middleware options
quiet: false,
noInfo: false,
lazy: true,
filename: "bundle.js",
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
publicPath: "/site/",
headers: { "X-Custom-Header": "yes" },
stats: { colors: true }
});
server.listen(8080, "localhost", function() {});
webpack-dev-server 配置的更多相关文章
- webpack dev server 配置 启动项目报错Error: listen EADDRINUSE
Error: listen EADDRINUSE 0.0.0.0:5601 它的意思是,端口5601被其他进程占用. 切换端口即可解决问题
- 笔记:配置 webpack dev server
笔记:配置 webpack dev server 安装 webpack-dev-server 组件 配置 webpack.config.js 配置 增加 html-webpack-plugin 组件 ...
- 配置Webpack Dev Server 实战操作方法步骤
本文摘要:配置 Webpack Dev Server 可以解决本地开发前端应用时,手动执行 webpack 命令或 yarn build 命令,再去浏览器中访问 dist/index.html 的麻烦 ...
- [Webpack] Access Webpack Dev Server from Mobile Safari on an iPhone
Testing your sites on mobile devices is a critical part of the development process. Webpack dev serv ...
- webpack dev server 和 sublime text 配合时需要注意的地方
参考:https://webpack.js.org/guides/development/ Adjusting Your Text Editor Some text editors have a &q ...
- vue2+webpack 开发环境配置
前提条件: 1.安装node.js https://nodejs.org/en/ 下载安装合适的平台 2.安装npm 第一步:初始化项目 新建文件夹 E:\app 推荐vue项目目录结构: confi ...
- 解决新版本webpack vue-cli生成文件没有dev.server.js问题
新版本webpack生成的dev.server.js 在webpack.dev.conf.js中 webpack.dev.conf.js const axios = require('axios') ...
- VUE开发请求本地数据的配置,旧版本dev-server.js,新版本webpack.dev.conf.js
VUE开发请求本地数据的配置,早期的vue-lic下面有dev-server.js和dev-client.js两文件,请求本地数据在dev-server.js里配置,最新的vue-webpack-te ...
- vue模拟后台数据,请求本地数据的配置(旧版本dev-server.js,新版本webpack.dev.conf.js)
最近学习一个vue-cli的项目,需要与后台进行数据交互,这里使用本地json数据来模仿后台数据交互流程.然而发现build文件夹下没有dev-server.js文件了,因为新版本的vue-webpa ...
- webpack 4 & dev server
webpack 4 & dev server proxy https://webpack.js.org/configuration/dev-server/#devserverproxy htt ...
随机推荐
- js与jQuery操作select大全
Js操作Select是很常见的,也是比较实用的,每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了. 一.js操作select部分 判断select选项中 是否存在V ...
- 精读JavaScript模式(三),new一个构造函数居然发生了什么?
一.前言 上个月底,爸爸因为事故突然离世,说心里话,现在看到'去世','爸爸'这样的字眼,眼泪都会忍不住在眼眶打转,还是需要时间治愈.最近也只是零碎的看了下东西,始终沉不下心去读书,直到今天还是决定捡 ...
- netty源码解解析(4.0)-7 线程模型-IO线程EventLoopGroup和NIO实现(二)
把NIO事件转换成对channel unsafe的调用或NioTask的调用 processSelectedKeys()方法是处理NIO事件的入口: private void processSelec ...
- typeof() 和 GetType()区是什么
1.typeof(x)中的x,必须是具体的类名.类型名称等,不可以是变量名称. 2.GetType()方法继承自Object,所以C#中任何对象都具有GetType()方法,它的作用和typeof() ...
- T-SQL:基础练习(杂)
1.返回 每月最后一天订单 SELECT orderid, orderdate, custid, empid FROM Sales.Orders WHERE orderdate = EOMONTH(o ...
- LeetCode算法笔记目录
贪心算法: LeetCode翻转矩阵后的得分-Python3<六> LeetCode根据身高重建队列-Python3<七> LeetCode 任务调度器-Python3< ...
- WebForm 【上传图片】【图片验证码】
上传图片(带水印) 1.获取要上传的图片 2.加水印 3.保存下来 using System.Drawing; --绘画类命名空间 图片最后要用绝对路径保存 Server.MapP ...
- vue VNode如何使用,是什么东西?
前言:element ui 中有些 demo 使用了 vue 的 VNode,但是 demo 毕竟不全,所以想要了解 VNode 到底是什么,如何写出符合自己业务的代码. vue 官网介绍:渲染函数 ...
- 在线客服兼容谷歌Chrome、苹果Safari、Opera浏览器的修改
纵览全网提供的众多号称兼容多浏览器的自动收缩在线客服,其实只兼容了IE和FF两种,当遇到谷歌Chrome.苹果Safari.Opera浏览器时鼠标还没点到客服按钮就会自动缩回,实用效果完全打折 以下代 ...
- 2017-07-20 在Maven Central发布中文API的Java库
知乎原链 相关问题: 哪些Java库有中文命名的API? 且记下随想. 之前没有发布过, 看了SO上的推荐:Publish a library to maven repositories 决定在son ...