Skip to content

Commit

Permalink
Added support for regular css, as well as css modules (with own loader)
Browse files Browse the repository at this point in the history
  • Loading branch information
weblogixx committed Jun 15, 2016
1 parent c65a790 commit 357b8c8
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"presets": [
"es2015-native-modules",
"stage-0",
"react",
"airbnb"
],
"plugins": [
"transform-decorators-legacy"
"transform-decorators-legacy",
"transform-object-rest-spread"
]
}
3 changes: 0 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"comma-dangle": 0,
"padded-blocks": 0,
"react/prefer-stateless-function": 0,
"react/jsx-no-bind": 0,
"strict": 0,
"no-unused-expressions": 0,
"no-underscore-dangle": [ "error", { "allowAfterThis": true }],
"import/no-unresolved": [ "error", "ignore": [
'config',
Expand Down
22 changes: 11 additions & 11 deletions conf/webpack/Base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* Webpack configuration base class
*/
'use strict';

const path = require('path');
const npmBase = path.join(__dirname, '../../node_modules');

Expand Down Expand Up @@ -69,7 +67,6 @@ class WebpackBaseConfig {
*/
get defaultSettings() {
return {
cache: true,
context: this.srcPathAbsolute,
debug: false,
devtool: 'eval',
Expand All @@ -92,48 +89,51 @@ class WebpackBaseConfig {
],
loaders: [
{
test: /\.css$/,
test: /\.cssmodule\.css$/,
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]'
]
},
{
test: /\.sass$/,
test: /^.((?!cssmodule).)*\.css$/,
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
'sass'
'css'
]
},
{
test: /\.scss$/,
test: /\.(sass|scss)$/,
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
'css',
'sass'
]
},
{
test: /\.less$/,
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
'css',
'less'
]
},
{
test: /\.styl$/,
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
'css',
'stylus'
]
},
{
test: /\.(png|jpg|gif|mp4|ogg|svg|woff|woff2)$/,
loaders: ['file']
},
{
test: /\.json$/,
loaders: 'json'
},
{
test: /\.(js|jsx)$/,
include: [].concat(
Expand Down
2 changes: 0 additions & 2 deletions conf/webpack/Dev.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* Default dev server configuration.
*/
'use strict';

const webpack = require('webpack');
const WebpackBaseConfig = require('./Base');

Expand Down
2 changes: 0 additions & 2 deletions conf/webpack/Dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Dist configuration. Used to build the
* final output when running npm run dist.
*/
'use strict';

const webpack = require('webpack');
const WebpackBaseConfig = require('./Base');

Expand Down
1 change: 0 additions & 1 deletion conf/webpack/Test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Default test configuration.
*/
'use strict';
const WebpackBaseConfig = require('./Base');
const webpack = require('webpack');

Expand Down
1 change: 0 additions & 1 deletion conf/webpack/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const dev = require('./Dev');
const dist = require('./Dist');
const test = require('./Test');
Expand Down
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const webpackCfg = require('./webpack.config')('test');

module.exports = function karmaConfig(config) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"posttest": "npm run lint",
"test:watch": "karma start --autoWatch=true --singleRun=false --reporters=mocha,coverage",
"serve:dev": "webpack-dev-server --open --env dev",
"serve:dist": "webpack-dev-server --hot --inline --open --progress --env dist -p",
"serve:dist": "webpack-dev-server --open --env dist -p --progress",
"dist": "npm run clean && npm run copy && webpack --progress --bail --env dist -p",
"lint": "eslint ./src",
"clean": "rimraf dist/*",
Expand Down Expand Up @@ -42,11 +42,11 @@
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-polyfill": "^6.9.0",
"babel-preset-airbnb": "^2.0.0",
"babel-preset-es2015-native-modules": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.5.0",
"copyfiles": "^0.2.1",
"css-loader": "^0.23.1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import cssmodules from 'react-css-modules';
import styles from './app.css';
import styles from './app.cssmodule.css';

const yeomanImage = require('../images/yeoman.png');

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/config/base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Settings configured here will be merged into the final config object.
export default {
};
4 changes: 1 addition & 3 deletions src/config/dev.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

import baseConfig from './base';

const config = {
appEnv: 'dev'
appEnv: 'dev',
};

export default Object.freeze(Object.assign({}, baseConfig, config));
4 changes: 1 addition & 3 deletions src/config/dist.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

import baseConfig from './base';

const config = {
appEnv: 'dist'
appEnv: 'dist',
};

export default Object.freeze(Object.assign({}, baseConfig, config));
4 changes: 1 addition & 3 deletions src/config/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

import baseConfig from './base';

const config = {
appEnv: 'test'
appEnv: 'test',
};

export default Object.freeze(Object.assign({}, baseConfig, config));
2 changes: 0 additions & 2 deletions test/config/ConfigTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import config from 'config';

describe('Application Environment', () => {
Expand Down
2 changes: 0 additions & 2 deletions test/loadtests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Add support for Promise objects via polyfills
import 'babel-polyfill';

Expand Down
9 changes: 6 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
'use strict';
/* eslint no-console: "off" */
const webpackConfigs = require('./conf/webpack');
const defaultConfig = 'dev';

module.exports = (configName) => {

// If there was no configuration give, assume default
const requestedConfig = configName || defaultConfig;

// Return a new instance of the webpack config
// or the default one if it cannot be found.
let LoadedConfig = defaultConfig;

if (webpackConfigs[configName] !== undefined) {
LoadedConfig = webpackConfigs[configName];
if (webpackConfigs[requestedConfig] !== undefined) {
LoadedConfig = webpackConfigs[requestedConfig];
} else {
console.warn(`
Provided environment "${configName}" was not found.
Expand Down

0 comments on commit 357b8c8

Please sign in to comment.