Skip to content

Commit a1be85e

Browse files
committed
Move css modules identifier name to webpack/constants
1 parent bc42a42 commit a1be85e

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"version": "2.3.0",
55
"license": "MIT",
66
"main": "client/index.js",
7-
"config": {
8-
"css": "[name]__[local]__[hash:base64:5]"
9-
},
107
"repository": {
118
"type": "git",
129
"url": "https://github.com/combine/universal-react-redux.git"

server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require('app-module-path').addPath('common/js');
88
// css-modules-require-hook package allows us to require css files on the server.
99
require('css-modules-require-hook')({
1010
extensions: ['.scss'],
11-
generateScopedName: require('../package.json').config.css,
11+
generateScopedName: require('../webpack/constants').CSS_MODULES_IDENTIFIER,
1212
devMode: process.env.NODE_ENV === 'development'
1313
});
1414

webpack/constants.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ export const OUTPUT_PATH = process.env.OUTPUT_PATH || 'dist/';
1717
/* The asset host to use inside the built webpack files. In product, set the
1818
* ASSET_HOST environment variable.
1919
*/
20-
export const ASSET_HOST = process.env.ASSET_HOST || (DEV_SERVER_HOST_URL + '/' + OUTPUT_PATH);
20+
export const ASSET_HOST = (
21+
process.env.NODE_ENV === 'production'
22+
? process.env.ASSET_HOST || '/dist/'
23+
: process.env.ASSET_HOST || (DEV_SERVER_HOST_URL + '/' + OUTPUT_PATH)
24+
);
25+
26+
/* The identifier to use for css-modules.
27+
*/
28+
export const CSS_MODULES_IDENTIFIER = '[name]__[local]__[hash:base64:5]';
2129

2230
/* Paths for webpack to resolve into non-relative directories, so that instead
2331
* of having to use relative paths:

webpack/development.hot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { DEV_SERVER_PORT, DEV_SERVER_HOSTNAME, DEV_SERVER_HOST_URL } from './constants';
2+
import { DEV_SERVER_PORT, DEV_SERVER_HOSTNAME, DEV_SERVER_HOST_URL, CSS_MODULES_IDENTIFIER } from './constants';
33
import WebpackDevServer from 'webpack-dev-server';
44
import path from 'path';
55
import webpack from 'webpack';
@@ -31,7 +31,7 @@ const loaders = [
3131
options: {
3232
modules: true,
3333
importLoaders: 3,
34-
localIdentName: packageJson.config.css
34+
localIdentName: CSS_MODULES_IDENTIFIER
3535
}
3636
},
3737
'postcss-loader'
@@ -46,7 +46,7 @@ const loaders = [
4646
options: {
4747
modules: true,
4848
importLoaders: 3,
49-
localIdentName: packageJson.config.css
49+
localIdentName: CSS_MODULES_IDENTIFIER
5050
}
5151
},
5252
'postcss-loader',

webpack/development.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import baseConfig from './base';
22
import ExtractTextPlugin from 'extract-text-webpack-plugin';
3-
import packageJson from '../package.json';
3+
import { CSS_MODULES_IDENTIFIER } from './constants';
44

55
const plugins = [
66
new ExtractTextPlugin('styles.css')
@@ -23,7 +23,7 @@ const loaders = [
2323
modules: true,
2424
minimize: false,
2525
importLoaders: 1,
26-
localIdentName: packageJson.config.css
26+
localIdentName: CSS_MODULES_IDENTIFIER
2727
}
2828
},
2929
{ loader: 'postcss-loader' },

webpack/production.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import webpack from 'webpack';
22
import baseConfig from './base';
3+
import { CSS_MODULES_IDENTIFIER } from './constants';
34
import CompressionPlugin from 'compression-webpack-plugin';
45
import ExtractTextPlugin from 'extract-text-webpack-plugin';
56

@@ -28,7 +29,15 @@ const loaders = [
2829
loader: ExtractTextPlugin.extract({
2930
fallback: 'style-loader',
3031
use: [
31-
{ loader: 'css-loader' },
32+
{
33+
loader: 'css-loader',
34+
options: {
35+
modules: true,
36+
minimize: false,
37+
importLoaders: 1,
38+
localIdentName: CSS_MODULES_IDENTIFIER
39+
}
40+
},
3241
{ loader: 'postcss-loader' },
3342
{ loader: 'sass-loader' }
3443
]

0 commit comments

Comments
 (0)