@@ -14,6 +14,7 @@ const fs = require('fs');
14
14
const autoprefixer = require ( 'autoprefixer' ) ;
15
15
const webpack = require ( 'webpack' ) ;
16
16
const CaseSensitivePathsPlugin = require ( 'case-sensitive-paths-webpack-plugin' ) ;
17
+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
17
18
const WatchMissingNodeModulesPlugin = require ( 'react-dev-utils/WatchMissingNodeModulesPlugin' ) ;
18
19
const getClientEnvironment = require ( './env' ) ;
19
20
const paths = require ( './paths' ) ;
@@ -28,6 +29,11 @@ const env = getClientEnvironment(publicUrl);
28
29
// We're loading package.json to get project name
29
30
const packageJSON = require ( paths . appPackageJson ) ;
30
31
32
+ const publicPath = './' ;
33
+ const cssFilename = 'style.css' ;
34
+ const extractTextPluginOptions = {
35
+ publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' )
36
+ } ;
31
37
// This is the development configuration.
32
38
// It is focused on developer experience and fast rebuilds.
33
39
// The production configuration is different and lives in a separate file.
@@ -58,7 +64,7 @@ module.exports = {
58
64
filename : 'index.js' ,
59
65
library : `__EPL_${ packageJSON . name } ` ,
60
66
libraryTarget : 'window' ,
61
- publicPath : '/'
67
+ publicPath : publicPath
62
68
} ,
63
69
resolve : {
64
70
// This allows you to set a fallback for where Webpack should look for modules.
@@ -132,7 +138,7 @@ module.exports = {
132
138
] ,
133
139
loader : 'file-loader' ,
134
140
options : {
135
- name : 'static/ media/[name].[hash:8].[ext]'
141
+ name : 'media/[name].[hash:8].[ext]'
136
142
}
137
143
} ,
138
144
// "url" loader works like "file" loader except that it embeds assets
@@ -143,7 +149,7 @@ module.exports = {
143
149
loader : 'url-loader' ,
144
150
options : {
145
151
limit : 10000 ,
146
- name : 'static/ media/[name].[hash:8].[ext]'
152
+ name : 'media/[name].[hash:8].[ext]'
147
153
}
148
154
} ,
149
155
// Process JS with Babel.
@@ -169,38 +175,49 @@ module.exports = {
169
175
// in development "style" loader enables hot editing of CSS.
170
176
{
171
177
test : / \. c s s $ / ,
172
- use : [
173
- 'style-loader' ,
174
- {
175
- loader : 'css-loader' ,
176
- options : {
177
- importLoaders : 1
178
- }
179
- } ,
180
- {
181
- loader : 'postcss-loader' ,
182
- options : {
183
- ident : 'postcss' , // https://webpack.js.org/guides/migrating/#complex-options
184
- plugins : ( ) => [
185
- autoprefixer ( {
186
- browsers : [
187
- '>1%' ,
188
- 'last 4 versions' ,
189
- 'Firefox ESR' ,
190
- 'not ie < 9' // React doesn't support IE8 anyway
191
- ]
192
- } )
178
+ loader : ExtractTextPlugin . extract (
179
+ Object . assign (
180
+ {
181
+ fallback : 'style-loader' ,
182
+ use : [
183
+ {
184
+ loader : 'css-loader' ,
185
+ options : {
186
+ importLoaders : 1
187
+ }
188
+ } ,
189
+ {
190
+ loader : 'postcss-loader' ,
191
+ options : {
192
+ ident : 'postcss' , // https://webpack.js.org/guides/migrating/#complex-options
193
+ plugins : ( ) => [
194
+ autoprefixer ( {
195
+ browsers : [
196
+ '>1%' ,
197
+ 'last 4 versions' ,
198
+ 'Firefox ESR' ,
199
+ 'not ie < 9' // React doesn't support IE8 anyway
200
+ ]
201
+ } )
202
+ ]
203
+ }
204
+ }
193
205
]
194
- }
195
- }
196
- ]
206
+ } ,
207
+ extractTextPluginOptions
208
+ )
209
+ )
210
+ // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
197
211
}
198
212
// TODO elm-webpack-loader
199
213
// ** STOP ** Are you adding a new loader?
200
214
// Remember to add the new extension(s) to the "url" loader exclusion list.
201
215
]
202
216
} ,
203
217
plugins : [
218
+ new ExtractTextPlugin ( {
219
+ filename : cssFilename
220
+ } ) ,
204
221
// Makes some environment variables available to the JS code, for example:
205
222
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
206
223
new webpack . DefinePlugin ( env . stringified ) ,
0 commit comments