UNPKG

2.82 kBJavaScriptView Raw
1var path = require('path');
2var webpack = require('webpack');
3var HtmlWebpackPlugin = require('html-webpack-plugin');
4var host = "localhost";
5var port = "8088";
6var md5 = new Date() * 1;
7
8// host可以改为ip 用于手机测试
9module.exports = {
10 host: host,
11 port: port,
12 resolve: {
13 root: path.resolve(__dirname, 'page/src'),
14 extensions: ['', '.js', '.jsx']
15 },
16 entry: {
17 main: [
18 path.resolve(__dirname, 'page/src/main')
19 ],
20 },
21 devtool: 'cheap-source-map', //https://github.com/webpack/docs/wiki/configuration#devtool
22 output: {
23 path: path.join(__dirname, 'page/build'),
24 filename: '[name]_'+ md5 +'.js',
25 chunkFilename: "[id].chunk_" + md5 +".js",
26 publicPath: '', //网站运行时的访问路径
27 },
28 plugins: [
29 new webpack.optimize.OccurenceOrderPlugin(),
30 // Webpack 提供了设置环境变量来优化代码
31 new webpack.DefinePlugin({
32 'process.env': {
33 'NODE_ENV': JSON.stringify('production')
34 }
35 }),
36 new webpack.optimize.UglifyJsPlugin({
37 compressor: {
38 warnings: false
39 }
40 }),
41 // 热替换 防止报错插件
42 new webpack.HotModuleReplacementPlugin(),
43 new webpack.NoErrorsPlugin(),
44 new webpack.optimize.DedupePlugin(),
45 new HtmlWebpackPlugin({
46 filename: 'index.html',
47 template: path.join(__dirname, 'page/src/index.html'),
48 chunks: ['main'],
49 inject: true
50 }),
51 new HtmlWebpackPlugin({
52 filename: 'error.jade',
53 template: path.join(__dirname, 'page/src/error.jade'),
54 inject: false
55 })
56 ],
57 module: {
58 loaders: [
59 {
60 test: /\.jsx?$/,// .js .jsx
61 loader: 'babel', // 'babel-loader' is also a legal name to reference
62 include: [
63 // 只去解析运行目录下的 src文件夹
64 path.join(__dirname, 'page/src'),
65 ],
66 },
67 {
68 test: /\.css$/,
69 // loader: ExtractTextPlugin.extract("style-loader", "css-loader")
70 loader: 'style-loader!css-loader!less-loader'
71 },
72 {
73 test: /\.less$/,
74 // loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
75 loader: 'style-loader!css-loader!less-loader'
76 },
77 {
78 test: /\.(png|jpg|gif|svg)$/,
79 //图片文件使用 url-loader 来处理,小于8kb的直接转为base64
80 loader: 'url-loader?limit=2048&name=images/[hash:8].[name].[ext]'
81 }
82 ]
83 }
84};