Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Commit 547beaa

Browse files
committed
Update style loader to to export styles in desired way
1 parent 66cceee commit 547beaa

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

config/webpack.config.dev.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const fs = require('fs');
1414
const autoprefixer = require('autoprefixer');
1515
const webpack = require('webpack');
1616
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
17+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
1718
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
1819
const getClientEnvironment = require('./env');
1920
const paths = require('./paths');
@@ -28,6 +29,11 @@ const env = getClientEnvironment(publicUrl);
2829
// We're loading package.json to get project name
2930
const packageJSON = require(paths.appPackageJson);
3031

32+
const publicPath = './';
33+
const cssFilename = 'style.css';
34+
const extractTextPluginOptions = {
35+
publicPath: Array(cssFilename.split('/').length).join('../')
36+
};
3137
// This is the development configuration.
3238
// It is focused on developer experience and fast rebuilds.
3339
// The production configuration is different and lives in a separate file.
@@ -58,7 +64,7 @@ module.exports = {
5864
filename: 'index.js',
5965
library: `__EPL_${packageJSON.name}`,
6066
libraryTarget: 'window',
61-
publicPath: '/'
67+
publicPath: publicPath
6268
},
6369
resolve: {
6470
// This allows you to set a fallback for where Webpack should look for modules.
@@ -132,7 +138,7 @@ module.exports = {
132138
],
133139
loader: 'file-loader',
134140
options: {
135-
name: 'static/media/[name].[hash:8].[ext]'
141+
name: 'media/[name].[hash:8].[ext]'
136142
}
137143
},
138144
// "url" loader works like "file" loader except that it embeds assets
@@ -143,7 +149,7 @@ module.exports = {
143149
loader: 'url-loader',
144150
options: {
145151
limit: 10000,
146-
name: 'static/media/[name].[hash:8].[ext]'
152+
name: 'media/[name].[hash:8].[ext]'
147153
}
148154
},
149155
// Process JS with Babel.
@@ -169,38 +175,49 @@ module.exports = {
169175
// in development "style" loader enables hot editing of CSS.
170176
{
171177
test: /\.css$/,
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+
}
193205
]
194-
}
195-
}
196-
]
206+
},
207+
extractTextPluginOptions
208+
)
209+
)
210+
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
197211
}
198212
// TODO elm-webpack-loader
199213
// ** STOP ** Are you adding a new loader?
200214
// Remember to add the new extension(s) to the "url" loader exclusion list.
201215
]
202216
},
203217
plugins: [
218+
new ExtractTextPlugin({
219+
filename: cssFilename
220+
}),
204221
// Makes some environment variables available to the JS code, for example:
205222
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
206223
new webpack.DefinePlugin(env.stringified),

config/webpack.config.prod.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getClientEnvironment = require('./env');
2121

2222
// Webpack uses `publicPath` to determine where the app is being served from.
2323
// It requires a trailing slash, or the file assets will get an incorrect path.
24-
const publicPath = paths.servedPath;
24+
const publicPath = './'; //paths.servedPath;
2525
// Some apps do not use client-side routing with pushState.
2626
// For these, "homepage" can be set to "." to enable relative asset paths.
2727
const shouldUseRelativeAssetPaths = publicPath === './';
@@ -42,7 +42,7 @@ if (env.stringified['process.env'].NODE_ENV !== '"production"') {
4242
const packageJSON = require(paths.appPackageJson);
4343

4444
// Note: defined here because it will be used more than once.
45-
const cssFilename = 'static/css/[name].[contenthash:8].css';
45+
const cssFilename = '[name].[contenthash:8].css';
4646

4747
// ExtractTextPlugin expects the build output to be flat.
4848
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
@@ -152,7 +152,7 @@ module.exports = {
152152
],
153153
loader: 'file-loader',
154154
options: {
155-
name: 'static/media/[name].[hash:8].[ext]'
155+
name: 'media/[name].[hash:8].[ext]'
156156
}
157157
},
158158
// "url" loader works just like "file" loader but it also embeds
@@ -162,7 +162,7 @@ module.exports = {
162162
loader: 'url-loader',
163163
options: {
164164
limit: 10000,
165-
name: 'static/media/[name].[hash:8].[ext]'
165+
name: 'media/[name].[hash:8].[ext]'
166166
}
167167
},
168168
// Process JS with Babel.

0 commit comments

Comments
 (0)