UNPKG

5.08 kBJavaScriptView Raw
1var webpack = require("webpack")
2var path = require("path")
3var HtmlWebpackPlugin = require('html-webpack-plugin')
4var CopyWebpackPlugin = require('copy-webpack-plugin')
5var ExtractTextPlugin = require("extract-text-webpack-plugin")
6//const marauderDebug = require('sinamfe-marauder-debug')
7const es3ifyWebpackPlugin = require('es3ify-webpack-plugin-v2')
8const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
9//const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
10const merge = require('webpack-merge')
11var env = process.env.NODE_ENV
12var plugins = []
13
14var projectRootPath = path.resolve(__dirname, './')
15//node环境变量,生产环境:production,开发环境:development
16plugins.push(new webpack.DefinePlugin({
17 "process.env.NODE_ENV": JSON.stringify(env)
18}))
19plugins.push(new webpack.optimize.ModuleConcatenationPlugin())
20plugins.push(new webpack.ExtendedAPIPlugin())
21plugins.push(new webpack.DllReferencePlugin({
22 context: __dirname,
23 manifest: merge(require('./vendor/shim.manifest.json'), require('./vendor/vendor.manifest.json')),
24}))
25
26plugins.push(new es3ifyWebpackPlugin())
27plugins.push(new HtmlWebpackPlugin({
28 title: '企业开发平台', //标题
29 favicon: './assets/img/favicon.ico', //favicon路径
30 filename: 'index.html', //生成的html存放路径,相对于 path
31 template: 'index.html', //html模板路径
32 chunks: ['edf', 'bundle', 'icon', 'greenTheme'],
33 hash: false,
34 inject: 'body', //允许插件修改哪些内容,包括head与body`
35 minify: { //压缩HTML文件
36 removeComments: true, //移除HTML中的注释
37 collapseWhitespace: true, //删除空白符与换行符
38 removeAttributeQuotes: true
39 }
40}))
41
42plugins.push(new ExtractTextPlugin('[name].[hash:8].css'))
43
44/*
45plugins.push(new OptimizeCssAssetsPlugin(
46 {
47 cssProcessorOptions: { discardComments: { removeAll: true } },
48 canPrint: false
49 }
50))
51*/
52
53plugins.push(new CopyWebpackPlugin([{
54 from: './robots.txt',
55 to: 'robots.txt',
56 toType: 'file'
57}]))
58
59//plugins.push(new marauderDebug())
60plugins.push(new LodashModuleReplacementPlugin)
61
62plugins.push(new webpack.optimize.CommonsChunkPlugin({
63 names: ['edf'],
64 filename: '[name].[hash:8].min.js',
65 minChunks: Infinity
66}))
67
68plugins.push(new CopyWebpackPlugin([{
69 from: './vendor',
70 to: './vendor',
71 ignore: ['.*']
72}]))
73
74module.exports = {
75 devtool: 'cheap-module-eval-source-map', //devtool: 'cheap-module-eval-source-map',
76 entry: {
77 bundle: "./index.js",
78 edf: ["edf-app-loader", "edf-meta-engine", "edf-component", "edf-consts", "edf-utils", "webapi"],
79 businessBlueTheme: "./assets/styles/businessBlue.less",
80 blackTheme: "./assets/styles/black.less",
81 greenTheme: "./assets/styles/green.less",
82 orangeTheme: "./assets/styles/orange.less",
83 blueTheme: "./assets/styles/blue.less",
84 yellowTheme: "./assets/styles/yellow.less",
85 icon: "./component/assets/style/iconset.less",
86
87 },
88
89 output: {
90 path: path.join(__dirname, "/dist/"),
91 filename: '[name].[hash:8].min.js',
92 chunkFilename: '[name].[hash:8].chunk.js'
93 },
94
95 resolve: {
96 extensions: [".js"],
97 alias: {
98 'edf-app-loader': path.resolve(projectRootPath, './app-loader/index.js'),
99 'edf-meta-engine': path.resolve(projectRootPath, './meta-engine/index.js'),
100 'edf-component': path.resolve(projectRootPath, './component/index.js'),
101 'edf-utils': path.resolve(projectRootPath, './utils/index.js'),
102 'webapi': path.resolve(projectRootPath, './api/index.js'),
103 'edf-consts': path.resolve(projectRootPath, './constant/consts.js'),
104 'eharts': path.resolve(projectRootPath, './vendor/echarts.min.js'),
105 'zrender': path.resolve(projectRootPath, './vendor/zrender.min.js')
106 }
107 },
108 externals: {
109 "echarts": 'echarts',
110 "zrender": 'zrender',
111 },
112 module: {
113 rules: [{
114 test: /\.(css|less)/,
115 use: ExtractTextPlugin.extract({
116 fallback: 'style-loader',
117 use: ['css-loader', 'less-loader']
118 })
119 }, {
120 test: /\.js?$/,
121 exclude: /node_modules/,
122 use: [{
123 loader: 'babel-loader',
124 options: {
125 cacheDirectory: true
126 }
127 }]
128 }, {
129 test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif|mp4|webm)(\?\S*)?$/,
130 use: {
131 loader: 'url-loader',
132 options: {
133 name: '[name].[hash:8].[ext]',
134 limit: 8192
135 }
136 }
137 }],
138 },
139 devServer: {
140 contentBase: './dist/',
141 proxy: {
142 // '/v1/*': 'http://127.0.0.1:8008/',
143 }
144 },
145 plugins: plugins
146}