UNPKG

2.32 kBJavaScriptView Raw
1var path = require('path');
2var webpack = require('webpack');
3var HtmlWebpackPlugin = require('html-webpack-plugin');
4var host = "localhost";
5var port = "8088";
6
7// host可以改为ip 用于手机测试
8module.exports = {
9 host: host,
10 port: port,
11 resolve: {
12 root: path.resolve(__dirname, 'page/src'),
13 extensions: ['', '.js', '.jsx']
14 },
15 entry: {
16 main: [
17 'webpack-dev-server/client?http://' + host + ':' + port,
18 'webpack/hot/only-dev-server',
19 path.resolve(__dirname, 'page/src/main')
20 ],
21 },
22 devtool: 'cheap-source-map', //https://github.com/webpack/docs/wiki/configuration#devtool
23 output: {
24 path: path.join(__dirname, 'build'),
25 filename: '[name].js',
26 chunkFilename: "[id].chunk.js",
27 publicPath: '', //网站运行时的访问路径
28 },
29 plugins: [
30 // 热替换 防止报错插件
31 new webpack.HotModuleReplacementPlugin(),
32 new webpack.NoErrorsPlugin(),
33 new webpack.optimize.DedupePlugin(),
34 new HtmlWebpackPlugin({
35 filename: 'index.html',
36 template: path.join(__dirname, 'page/src/index.html'),
37 chunks: ['main'],
38 inject: true
39 })
40 ],
41 module: {
42 loaders: [
43 {
44 test: /\.jsx?$/,// .js .jsx
45 loader: 'babel', // 'babel-loader' is also a legal name to reference
46 include: [
47 // 只去解析运行目录下的 src文件夹
48 path.join(process.cwd(), 'page/src'),
49 ],
50 },
51 {
52 test: /\.css$/,
53 // loader: ExtractTextPlugin.extract("style-loader", "css-loader")
54 loader: 'style-loader!css-loader!less-loader'
55 },
56 {
57 test: /\.less$/,
58 // loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
59 loader: 'style-loader!css-loader!less-loader'
60 },
61 {
62 test: /\.(png|jpg|gif|svg)$/,
63 //图片文件使用 url-loader 来处理,小于8kb的直接转为base64
64 loader: 'url-loader?limit=2048&name=images/[hash:8].[name].[ext]'
65 }
66 ]
67 }
68};