1 Star 0 Fork 0

Ethan/blog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.server.config.js 6.17 KB
一键复制 编辑 原始数据 按行查看 历史
贺传华 提交于 2017-04-06 11:48 . 服务端渲染
var path = require('path')
var fs = require('fs')
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var CleanPlugin = require('clean-webpack-plugin')
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin
var nodeModules = {}
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod
})
module.exports = [{
entry: {
vendor: ['react','redux','react-redux','react-router','redux-thunk','react-dom'],
bundle: './src/client'
},
output: {
path: path.resolve(__dirname, "./dist"), //静态资源会再这目录下
filename: "js/[name].[chunkHash:8].js",
chunkFilename: "js/[name].[chunkHash:8].js",
publicPath: "/" //html里面的引用路径会变成这个
},
resolve: {
extensions: ['', '.js', '.less', '.css', '.png', '.jpg'], //第一个是空字符串! 对应不需要后缀的情况.
root: './src',
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
//loader: 'babel?presets[]=es2015&presets[]=react'
loader: 'babel-loader',
query: {
presets: [["es2015", { "loose": true }],'react','stage-0'],
// plugins: ["transform-es5-property-mutators","transform-jscript","transform-es3-property-literals","transform-es3-member-expression-literals",]
}
}, {
test: /\.css$/,
exclude: /node_modules/,
/*loader: "style!css!less",*/
loader: ExtractTextPlugin.extract('style', 'css')
}, {
test: /\.less$/,
exclude: /node_modules/,
/*loader: "style!css!less",*/
loader: ExtractTextPlugin.extract('style', 'css!less')
}, {
test: /\.(png|jpg|jpeg|gif)$/,
exclude: /node_modules/,
loader: 'url?limit=10000&name=img/[name].[hash].[ext]'
}, {
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
exclude: /node_modules/,
loader: 'url?prefix=font/&limit=10000&name=font/[name].[ext]'
}],
// postLoaders: [{
// test: /\.js$/,
// exclude: /node_modules/,
// loaders: ['es3ify-loader'],
// }]
},
plugins: [
new HtmlWebpackPlugin({
//favicon:path.join(__dirname,'../src/favicon.ico'),
title: "我的个人网站",
template: path.join(__dirname,'./src/index.html'),
filename: 'index.ejs',
inject:'body',
html:'<%- __html__ %>',
initialData:'window.__INITIAL_STATE__ = <%- __state__ %>',
hash:false, //为静态资源生成hash值
minify:{ //压缩HTML文件
removeComments:false, //移除HTML中的注释
collapseWhitespace:false //删除空白符与换行符
}
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
//new CleanPlugin(['dist']),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
//drop_debugger: true,
drop_console: true
}
}),
new webpack.optimize.OccurenceOrderPlugin(), //按引用频度来排序 ID,以便达到减少文件大小的效果
new ExtractTextPlugin('css/[name].[hash:8].css', {
allChunks: true
}),
new CommonsChunkPlugin({
name: "vendor",
//filename:"vendor.js",
minChunks: Infinity //Infinity
}),
],
},
{
target: "node",
context: path.join(__dirname, "./"),
entry: {
index: [
'./src/server'
]
},
externals: nodeModules,
output: {
path: path.resolve(__dirname, "./dist"), //静态资源会再这目录下
filename: "server.js",
publicPath: "/", //html里面的引用路径会变成这个
libraryTarget: "commonjs2"
},
resolve: {
extensions: ['', '.js', '.less', '.css', '.png', '.jpg'], //第一个是空字符串! 对应不需要后缀的情况.
root: './src',
},
module: {
loaders: [{
test: /\.js$/,
//exclude: /node_modules/,
//loader: 'babel?presets[]=es2015&presets[]=react'
loader: 'babel-loader',
query: {
presets: [["es2015", { "loose": true }],'react','stage-0'],
// plugins: ["transform-es5-property-mutators","transform-jscript","transform-es3-property-literals","transform-es3-member-expression-literals",]
}
}, {
test: /\.json$/,
loader: "json-loader"
}, {
test: /\.css$/,
exclude: /node_modules/,
/*loader: "style!css!less",*/
loader: ExtractTextPlugin.extract('style', 'css')
}, {
test: /\.less$/,
exclude: /node_modules/,
/*loader: "style!css!less",*/
loader: ExtractTextPlugin.extract('style', 'css!less')
}, {
test: /\.(png|jpg|jpeg|gif)$/,
exclude: /node_modules/,
loader: 'url?limit=10000&name=img/[name].[hash].[ext]'
}, {
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
exclude: /node_modules/,
loader: 'url?prefix=font/&limit=10000&name=font/[name].[ext]'
}],
// postLoaders: [{
// test: /\.js$/,
// exclude: /node_modules/,
// loaders: ['es3ify-loader'],
// }]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
//new CleanPlugin(['dist/js']),
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false,
// //drop_debugger: true,
// drop_console: true
// }
// }),
new webpack.IgnorePlugin(/vertx/),
],
}]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/ethan1788/blog.git
[email protected]:ethan1788/blog.git
ethan1788
blog
blog
master

搜索帮助