18 Star 66 Fork 29

梅气灶/React-webpack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 3.02 KB
一键复制 编辑 原始数据 按行查看 历史
meichao 提交于 2017-10-11 14:33 . 添加postCss,加上了autoprefixer
/**
* Created by MC on 16/10/16.
*/
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var node_modules = path.resolve(__dirname, 'node_modules');
var pathToReact = path.resolve(node_modules, 'react/dist/react.min.js');
var pathToReactDom = path.resolve(node_modules, 'react-dom/dist/react-dom.min.js');
console.log("这里是路径:",path.resolve(__dirname, './app/routes'));
module.exports = {
entry: [
// 'webpack/hot/dev-server',
path.resolve(__dirname, './app/routes')
],
output: {
path: path.resolve(__dirname, './build'),
filename: 'js/bundle.js',
// publicPath:'http://localhost:8181/', //同样可以
publicPath:'/',
chunkFilename: "js/[name].bundle.min.js?ver=[chunkhash]"
},
devServer:{
// contentBase: '', //静态资源的目录 相对路径,相对于当前路径 默认为当前config所在的目录
// devtool: 'eval',
// hot: true, //自动刷新
inline: true,
port: 8181
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /^node_modules$/,
loader: 'babel',
},{
test: /\.(css|scss)$/,
loader: ExtractTextPlugin.extract("style", "css!sass!postcss")
},{
test: /\.(png|jpg|jpeg|gif|eot|woff|svg|ttf|woff2|appcache)(\?|$)/,
exclude: /^node_modules$/,
loader: 'file-loader?name=img/[name].[ext]'
}
]
},
resolve:{
alias: {
'react': pathToReact,
'react-dom':pathToReactDom
},
extensions: ['', '.js', '.jsx'], //后缀名自动补全
},
/*
* HtmlWebpackPlugin 这里会自动生成css和js文件,自己在build文件下创建的css文件和js文件目前未用到,但是先不删除,以防后期有变
* 有模板html文件,这样原先的 页面跳转了,title不能改变的问题
*/
plugins: [
new webpack.ProvidePlugin({
React: 'react',
ReactDOM: 'react-dom'
}),
new webpack.optimize.UglifyJsPlugin({minimize: true}), //使用uglifyJs压缩js代码
new webpack.optimize.OccurenceOrderPlugin(), //按引用频度来排序 ID,以便达到减少文件大小的效果
// new webpack.HotModuleReplacementPlugin(), //开启全局的 HMR 能力
new webpack.optimize.CommonsChunkPlugin('js/common.js'),
// new ExtractTextPlugin("css/[name].css"),
new ExtractTextPlugin("css/[name].[contenthash:6].css",{allChunks: true}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: `${__dirname}/build/index.html`,
inject: 'body',
hash: true
})
]
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/meichao/React-webpack.git
git@gitee.com:meichao/React-webpack.git
meichao
React-webpack
React-webpack
master

搜索帮助

Cb406eda 1850385 E526c682 1850385