@@ -44,30 +44,34 @@ const getAbsolutePath = (url) => path.resolve(__dirname, url);
44
44
const filename = '[name]' ;
45
45
46
46
function getWebpackConfigs ( ) {
47
- const webpackConfigs = [ ] ;
47
+ const webpackEntries = { } ;
48
+ const cssWebpackEntries = { } ;
49
+ const cssWebpackEntriesMin = { } ;
50
+ const webpackConfig = getJavaScriptWebpackConfig ( ) ;
51
+ const webpackConfigCss = getCssWebpackConfig ( ) ;
52
+ const webpackConfigCssMin = getCssWebpackConfig ( true ) ;
48
53
49
54
chunks . forEach ( ( chunk ) => {
50
55
const tsxPath = getAbsolutePath ( `${ chunk } /index.tsx` ) ;
51
56
const cssPath = getAbsolutePath ( `${ chunk } /index.scss` ) ;
52
-
53
- webpackConfigs . push ( getJavaScriptWebpackConfig ( tsxPath , chunk , 'commonjs' ) ) ;
54
- webpackConfigs . push ( getJavaScriptWebpackConfig ( tsxPath , chunk , false ) ) ;
55
- webpackConfigs . push ( getJavaScriptWebpackConfig ( tsxPath , `${ chunk } .min` , 'commonjs' ) ) ;
56
-
57
- webpackConfigs . push ( getCssWebpackConfig ( cssPath , chunk ) ) ;
58
- webpackConfigs . push ( getCssWebpackConfig ( cssPath , `${ chunk } .min` ) ) ;
57
+ webpackEntries [ chunk ] = tsxPath ;
58
+ webpackEntries [ `${ chunk } .min` ] = tsxPath ;
59
+ cssWebpackEntries [ chunk ] = cssPath ;
60
+ cssWebpackEntriesMin [ `${ chunk } .min` ] = cssPath ;
59
61
} ) ;
60
62
61
- return webpackConfigs ;
63
+ webpackConfig . entry = webpackEntries ;
64
+ webpackConfigCss . entry = cssWebpackEntries ;
65
+ webpackConfigCssMin . entry = cssWebpackEntriesMin ;
66
+
67
+ return [ webpackConfig , webpackConfigCss , webpackConfigCssMin ] ;
62
68
}
63
69
64
- function getCommonWebpackParams ( entryPath , chunk , { isCss, modules} ) {
65
- const entry = { [ chunk ] : entryPath } ;
70
+ function getCommonWebpackParams ( { isCss} = { } ) {
66
71
return {
67
- entry,
68
72
output : {
69
73
path : getAbsolutePath ( '../build' ) ,
70
- filename : `${ filename } ${ isCss ? '.css' : '' } ${ modules === false ? '.es' : '' } .js` ,
74
+ filename : `${ filename } ${ isCss ? '.css' : '' } .js` ,
71
75
libraryTarget : 'umd' ,
72
76
} ,
73
77
resolve : {
@@ -97,21 +101,36 @@ function getMaterialExternals() {
97
101
return externals ;
98
102
}
99
103
100
- function getJavaScriptWebpackConfig ( entryPath , chunk , modules ) {
104
+ const materialExternals = getMaterialExternals ( ) ;
105
+
106
+ function getJavaScriptWebpackConfig ( ) {
101
107
return Object . assign (
102
- getCommonWebpackParams ( entryPath , chunk , { modules } ) , {
108
+ getCommonWebpackParams ( ) , {
103
109
externals : Object . assign (
104
110
{
105
111
'react' : 'react' ,
106
112
'classnames' : 'classnames' ,
107
113
'prop-types' : 'prop-types' ,
114
+ '@material/textfield/constants' : `@material/textfield/constants.js` ,
108
115
} ,
109
- getMaterialExternals ( ) ,
116
+ materialExternals ,
110
117
) ,
111
118
module : {
112
119
rules : [ {
113
120
test : / \. t s ( x ) ? $ / ,
114
121
loader : 'ts-loader' ,
122
+ } , {
123
+ test : / \. j s $ / ,
124
+ loader : 'babel-loader' ,
125
+ options : {
126
+ babelrc : false ,
127
+ compact : true ,
128
+ presets : [ [ 'es2015' , { modules : false } ] , 'react' ] ,
129
+ plugins : [
130
+ 'transform-class-properties' ,
131
+ 'transform-object-rest-spread' ,
132
+ ] ,
133
+ } ,
115
134
} ] ,
116
135
} ,
117
136
plugins : [
@@ -122,10 +141,9 @@ function getJavaScriptWebpackConfig(entryPath, chunk, modules) {
122
141
} ) ;
123
142
}
124
143
125
- function getCssWebpackConfig ( entryPath , chunk ) {
126
- const shouldMinify = chunk . includes ( '.min' ) ;
144
+ function getCssWebpackConfig ( shouldMinify ) {
127
145
return Object . assign (
128
- getCommonWebpackParams ( entryPath , chunk , { isCss : true } ) , {
146
+ getCommonWebpackParams ( { isCss : true } ) , {
129
147
module : {
130
148
rules : [ {
131
149
test : / \. s c s s $ / ,
@@ -155,5 +173,4 @@ function getCssWebpackConfig(entryPath, chunk) {
155
173
} ) ;
156
174
}
157
175
158
-
159
176
module . exports = getWebpackConfigs ( ) ;
0 commit comments