11const path = require ( 'path' ) ;
22const webpack = require ( 'webpack' ) ;
3- const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
3+ const WebpackBar = require ( 'webpackbar' ) ;
4+ const webpackMerge = require ( 'webpack-merge' ) ;
5+ const UglifyJsPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
6+ const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
7+ const OptimizeCSSAssetsPlugin = require ( 'optimize-css-assets-webpack-plugin' ) ;
48const CaseSensitivePathsPlugin = require ( 'case-sensitive-paths-webpack-plugin' ) ;
5- const deepAssign = require ( 'deep-assign' ) ;
6- const chalk = require ( 'chalk' ) ;
79const postcssConfig = require ( './postcssConfig' ) ;
10+ const CleanUpStatsPlugin = require ( './utils/CleanUpStatsPlugin' ) ;
11+
812const distFileBaseName = 'antd' ;
9- module . exports = function ( modules ) {
13+
14+ const svgRegex = / \. s v g ( \? v = \d + \. \d + \. \d + ) ? $ / ;
15+ const svgOptions = {
16+ limit : 10000 ,
17+ minetype : 'image/svg+xml' ,
18+ } ;
19+
20+ const imageOptions = {
21+ limit : 10000 ,
22+ } ;
23+
24+ function getWebpackConfig ( modules ) {
1025 const pkg = require ( path . join ( process . cwd ( ) , 'package.json' ) ) ;
1126 const babelConfig = require ( './getBabelCommonConfig' ) ( modules || false ) ;
1227
1328 const pluginImportOptions = [
1429 {
1530 style : true ,
16- libraryName : 'antd' ,
31+ libraryName : distFileBaseName ,
1732 libraryDirectory : 'components' ,
1833 } ,
1934 ] ;
20-
21- // if (distFileBaseName !== 'antd') { pluginImportOptions.push({ style:
22- // 'css', libraryDirectory: 'components', libraryName: 'antd', }) }
23-
2435 babelConfig . plugins . push ( [ require . resolve ( 'babel-plugin-import' ) , pluginImportOptions ] ) ;
2536
37+ if ( modules === false ) {
38+ babelConfig . plugins . push ( require . resolve ( './replaceLib' ) ) ;
39+ }
40+
2641 const config = {
2742 devtool : 'source-map' ,
2843
@@ -86,74 +101,75 @@ module.exports = function(modules) {
86101 } ,
87102 {
88103 test : / \. c s s $ / ,
89- use : ExtractTextPlugin . extract ( {
90- use : [
91- {
92- loader : 'css-loader' ,
93- options : {
94- sourceMap : true ,
95- } ,
96- } ,
97- {
98- loader : 'postcss-loader' ,
99- options : Object . assign ( { } , postcssConfig , { sourceMap : true } ) ,
104+ use : [
105+ MiniCssExtractPlugin . loader ,
106+ {
107+ loader : 'css-loader' ,
108+ options : {
109+ sourceMap : true ,
100110 } ,
101- ] ,
102- } ) ,
111+ } ,
112+ {
113+ loader : 'postcss-loader' ,
114+ options : Object . assign ( { } , postcssConfig , { sourceMap : true } ) ,
115+ } ,
116+ ] ,
103117 } ,
104118 {
105119 test : / \. l e s s $ / ,
106- use : ExtractTextPlugin . extract ( {
107- use : [
108- {
109- loader : 'css-loader' ,
110- options : {
111- sourceMap : true ,
112- } ,
113- } ,
114- {
115- loader : 'postcss-loader' ,
116- options : Object . assign ( { } , postcssConfig , { sourceMap : true } ) ,
120+ use : [
121+ MiniCssExtractPlugin . loader ,
122+ {
123+ loader : 'css-loader' ,
124+ options : {
125+ sourceMap : true ,
117126 } ,
118- {
119- loader : 'less-loader' ,
120- options : {
121- sourceMap : true ,
122- } ,
127+ } ,
128+ {
129+ loader : 'postcss-loader' ,
130+ options : Object . assign ( { } , postcssConfig , { sourceMap : true } ) ,
131+ } ,
132+ {
133+ loader : 'less-loader' ,
134+ options : {
135+ sourceMap : true ,
136+ javascriptEnabled : true ,
123137 } ,
124- ] ,
125- } ) ,
138+ } ,
139+ ] ,
140+ } ,
141+ // Images
142+ {
143+ test : svgRegex ,
144+ loader : 'url-loader' ,
145+ options : svgOptions ,
146+ } ,
147+ {
148+ test : / \. ( p n g | j p g | j p e g | g i f ) ( \? v = \d + \. \d + \. \d + ) ? $ / i,
149+ loader : 'url-loader' ,
150+ options : imageOptions ,
126151 } ,
127152 ] ,
128153 } ,
129154
130155 plugins : [
131- new ExtractTextPlugin ( { filename : '[name].css' , disable : false , allChunks : true } ) ,
132156 new CaseSensitivePathsPlugin ( ) ,
133157 new webpack . BannerPlugin ( `
134- ${ distFileBaseName } v${ pkg . version }
158+ ${ pkg . name } v${ pkg . version }
135159
136160Copyright 2017-present, ant-design-vue.
137161All rights reserved.
138162 ` ) ,
139- new webpack . ProgressPlugin ( ( percentage , msg , addInfo ) => {
140- const stream = process . stderr ;
141- if ( stream . isTTY && percentage < 0.71 ) {
142- stream . cursorTo ( 0 ) ;
143- stream . write ( `📦 ${ chalk . magenta ( msg ) } (${ chalk . magenta ( addInfo ) } )` ) ;
144- stream . clearLine ( 1 ) ;
145- } else if ( percentage === 1 ) {
146- console . log ( chalk . green ( '\nwebpack: bundle build is now finished.' ) ) ;
147- }
163+ new WebpackBar ( {
164+ name : '🚚 Ant Design Vue Tools' ,
165+ color : '#2f54eb' ,
148166 } ) ,
167+ new CleanUpStatsPlugin ( ) ,
149168 ] ,
150169 } ;
151170
152171 if ( process . env . RUN_ENV === 'PRODUCTION' ) {
153172 const entry = [ './index' ] ;
154- config . entry = {
155- [ `${ distFileBaseName } .min` ] : entry ,
156- } ;
157173 config . externals = {
158174 vue : {
159175 root : 'Vue' ,
@@ -164,38 +180,61 @@ All rights reserved.
164180 } ;
165181 config . output . library = distFileBaseName ;
166182 config . output . libraryTarget = 'umd' ;
167-
168- const uncompressedConfig = deepAssign ( { } , config ) ;
169-
170- config . plugins = config . plugins . concat ( [
171- new webpack . optimize . UglifyJsPlugin ( {
172- sourceMap : true ,
173- output : {
174- ascii_only : true ,
175- } ,
176- compress : {
177- warnings : false ,
178- } ,
179- } ) ,
180- new webpack . optimize . ModuleConcatenationPlugin ( ) ,
181- new webpack . LoaderOptionsPlugin ( { minimize : true } ) ,
182- new webpack . DefinePlugin ( {
183- 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV || 'production' ) ,
184- } ) ,
185- ] ) ;
186-
187- uncompressedConfig . entry = {
188- [ distFileBaseName ] : entry ,
183+ config . optimization = {
184+ minimizer : [
185+ new UglifyJsPlugin ( {
186+ cache : true ,
187+ parallel : true ,
188+ sourceMap : true ,
189+ uglifyOptions : {
190+ warnings : false ,
191+ } ,
192+ } ) ,
193+ ] ,
189194 } ;
190195
191- uncompressedConfig . plugins . push (
192- new webpack . DefinePlugin ( {
193- 'process.env.NODE_ENV' : JSON . stringify ( 'development' ) ,
194- } ) ,
195- ) ;
196+ // Development
197+ const uncompressedConfig = webpackMerge ( { } , config , {
198+ entry : {
199+ [ distFileBaseName ] : entry ,
200+ } ,
201+ mode : 'development' ,
202+ plugins : [
203+ new MiniCssExtractPlugin ( {
204+ filename : '[name].css' ,
205+ } ) ,
206+ ] ,
207+ } ) ;
196208
197- return [ config , uncompressedConfig ] ;
209+ // Production
210+ const prodConfig = webpackMerge ( { } , config , {
211+ entry : {
212+ [ `${ distFileBaseName } .min` ] : entry ,
213+ } ,
214+ mode : 'production' ,
215+ plugins : [
216+ new webpack . optimize . ModuleConcatenationPlugin ( ) ,
217+ new webpack . LoaderOptionsPlugin ( {
218+ minimize : true ,
219+ } ) ,
220+ new MiniCssExtractPlugin ( {
221+ filename : '[name].css' ,
222+ } ) ,
223+ ] ,
224+ optimization : {
225+ minimizer : [ new OptimizeCSSAssetsPlugin ( { } ) ] ,
226+ } ,
227+ } ) ;
228+
229+ return [ prodConfig , uncompressedConfig ] ;
198230 }
199231
200232 return config ;
201- } ;
233+ }
234+
235+ getWebpackConfig . webpack = webpack ;
236+ getWebpackConfig . svgRegex = svgRegex ;
237+ getWebpackConfig . svgOptions = svgOptions ;
238+ getWebpackConfig . imageOptions = imageOptions ;
239+
240+ module . exports = getWebpackConfig ;
0 commit comments