var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin'); //css单独打包
var HtmlWebpackPlugin = require('html-webpack-plugin'); //生成html var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'src'); //__dirname 中的src目录,以此类推
var APP_FILE = path.resolve(APP_PATH, 'App'); //根目录文件app.js地址
var BUILD_PATH = path.resolve(ROOT_PATH, '/pxq/dist'); //发布文件所存放的目录 module.exports = {
entry: {
app: APP_FILE
},
output: {
publicPath: '/pxq/dist/', //编译好的文件,在服务器的路径,这是静态资源引用路径
path: BUILD_PATH, //编译到当前目录
filename: '[name].js', //编译后的文件名字
chunkFilename: '[name].[chunkhash:5].min.js',
},
module: {
loaders: [{
test: /\.js$/,//使用正则匹配要处理的文件
exclude: /^node_modules$/,//排除不处理的目录
loader: 'babel',//要使用的loader
include: [APP_PATH]
}, {
test: /\.css$/,
exclude: /^node_modules$/,
loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer']),
include: [APP_PATH]
}, {
test: /\.less$/,
exclude: /^node_modules$/,
loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer', 'less']),
include: [APP_PATH]
}, {
test: /\.scss$/,
exclude: /^node_modules$/,
loader: ExtractTextPlugin.extract('style', ['css', 'autoprefixer', 'sass']),
include: [APP_PATH]
}, {
test: /\.(eot|woff|svg|ttf|woff2|gif|appcache)(\?|$)/,
exclude: /^node_modules$/,
loader: 'file-loader?name=[name].[ext]',
include: [APP_PATH]
}, {
test: /\.(png|jpg)$/,
exclude: /^node_modules$/,
loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]',
//注意后面那个limit的参数,当你图片大小小于这个限制的时候,会自动启用base64编码图片
include: [APP_PATH]
}, {
test: /\.jsx$/,
exclude: /^node_modules$/,
loaders: ['jsx', 'babel'],
include: [APP_PATH]
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development') //定义编译环境
}
}),
new HtmlWebpackPlugin({  //根据模板插入css/js等生成最终HTML
filename: '../index.html', //生成的html存放路径,相对于 path
template: './src/template/index.html', //html模板路径
hash: false,
}),
new ExtractTextPlugin('[name].css')
],
resolve: {
extensions: ['', '.js', '.jsx', '.less', '.scss', '.css'], //后缀名自动补全
}
};

比较实用的webpack配置代码的更多相关文章

  1. log4net实用配置代码

    log4net实用配置代码 <?xml version="1.0" encoding="utf-8" ?> <configuration> ...

  2. Webpack配置示例和详细说明

    /* * 请使用最新版本nodejs * 默认配置,是按生产环境的要求设置,也就是使用 webpack -p 命令就可以生成正式上线版本. * 也可以使用 webpack -d -w 命令,生成用于开 ...

  3. vue-cli#2.0 webpack 配置分析

    目录结构: ├── README.md ├── build │ ├── build.js │ ├── check-versions.js │ ├── dev-client.js │ ├── dev-s ...

  4. React配合Webpack实现代码分割与异步加载

    这是Webpack+React系列配置过程记录的第四篇.其他内容请参考: 第一篇:使用webpack.babel.react.antdesign配置单页面应用开发环境 第二篇:使用react-rout ...

  5. webpack配置这一篇就够

    最近看了一篇好文,根据这个文章重新梳理了一遍webpack打包过程,以前的一些问题也都清楚了,在这里分享一下,同时自己也做了一些小的调整 原文链接:http://www.jianshu.com/p/4 ...

  6. 前端工程化(二)---webpack配置

    导航 前端工程化(一)---工程基础目录搭建 前端工程化(二)---webpack配置 前端工程化(三)---Vue的开发模式 前端工程化(四)---helloWord 继续上一遍的配置,本节主要记录 ...

  7. vue全家桶安装以及修改webpack配置新增vue项目启动方式

    一.安装node环境(自带npm) 下载地址 二.替换下载源 // 淘宝 NPM 镜像 npm install -g cnpm --registry=https://registry.npm.taob ...

  8. vue-cli中webpack配置详解

    vue-cli是构建vue单页应用的脚手架,命令行输入vue init <template-name> <project-name>从而自动生成的项目模板,比较常用的模板有we ...

  9. storybook配置之基本配置和webpack配置

    默认配置 Storybook有一个默认的适合(suits)大型项目开发的webpack配置,假如你使用react app,他类似于创建一个react app的配置,并经过调整(tweaked ),使其 ...

随机推荐

  1. 学习笔记:GLSL Core Tutorial – Vertex Shader(内置变量说明)

    1.每个Vertex Shader都有用户定义的输入属性,例如:位置,法线向量和纹理坐标等.Vertex Shaders也接收一致变量(uniform variables). uniform vari ...

  2. 浅谈SQL Server 对于内存的管理

    简介 理解SQL Server对于内存的管理是对于SQL Server问题处理和性能调优的基本,本篇文章讲述SQL Server对于内存管理的内存原理. 二级存储(secondary storage) ...

  3. acm课程练习2--1002

    题目描述 Now, here is a fuction:  F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100)Can you find the ...

  4. HDU - 5276 YJC tricks time

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5276   Sample Input 99000 0   Sample Output 00:01:30 ...

  5. ubuntu apache 安装awstats 流量分析工具(命令方式)

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  6. MySQL+heartbeat+nfs做高可用

    一.环境准备节点两个node1:10.10.10.202node2:10.10.10.203nfs服务器:node3:10.10.10.204系统环境CentOS release 6.5 (Final ...

  7. asp 随机生成字符

    <%function rndNumLetters(num) randomize dim num0,num1,num2,num3,pass if num = "" or not ...

  8. Codeforces Round #363 (Div. 2) B. One Bomb (水题)

    B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. hadoop的安全模式

    在安全模式下:不能增.删.改操作:但可以查看. 查看hadoop是否i处于安全模式下: 执行命令:hadoop dfsadmin -safemode get 进入hadoop的安全模式下: 执行命令: ...

  10. C#入门经典(第五章-1)