UNPKG

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