-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.build.config.js
102 lines (96 loc) · 2.85 KB
/
webpack.build.config.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
/**
* webpack 构建配置
*/
/**
* Created by x on 11/23/15.
*/
var path = require('path');
/**
* 导入文件入口
* @type {{index: string, details: string}|exports|module.exports}
*/
var webpack = require('webpack');
//提取公用CSS
var ExtractTextPlugin = require("extract-text-webpack-plugin");
//var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
//动态HTML 插入
var HtmlWebpackPlugin = require('html-webpack-plugin');
var SplitByPathPlugin = require('webpack-split-by-path');
var node_modules = path.resolve(__dirname, 'node_modules');
var pathToSrc = path.resolve(__dirname, 'src');
var config = {
//未压缩的
//devtool: "source-map",
//不输出
devtool: "false",
/*--压缩过的--*/
//devtool:"cheap-source-map",
//devtool:"eval-source-map",
//入口文件配置
entry: {
app: [
path.resolve(__dirname, 'ts/index')
]
},
resolve: {
extensions: ['', '.js', '.jsx','.ts','.tsx']
},
//输出文件配置
output: {
path: path.resolve(__dirname, 'www/dist'),
chunkFilename: '[name].js',
filename: '[name].js',
publicPath: '/dist/'
},
module: {
loaders: [
{
test: /\.(js|jsx|tsx|ts)?$/,
//loaders: ['react-hot', 'babel','ts-loader'],
loaders: ['ts-loader'],
exclude: /node_modules/
},
{
test: /\.(le|c)ss$/, // Only .css files
loader: ExtractTextPlugin.extract('style', 'css!less') //'style!css' // Run both loaders
}
],
},
preLoaders: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ test: /\.js$/, loader: "source-map-loader" }
],
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new ExtractTextPlugin("app.css"),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
},
compress: {
warnings: false
}
}),
//commonsPlugin
/*new webpack.optimize.CommonsChunkPlugin({
name: "common",
filename:"common.js"
}),*/
new HtmlWebpackPlugin({
title: 'react ui组件123',
addLinkCss: ['/styles/iconfont.css'],
template: './template/index.ejs',
hash: true, //为静态资源生成hash值
}),
new SplitByPathPlugin([
{name: 'common', path: path.join(__dirname, 'node_modules')}
]
)
]
};
module.exports = config;