Skip to content

Commit 79e674d

Browse files
aulizkodavidnpma
authored andcommitted
fix: from css files to style attributes
This fix also supports react 0.14.0-rc1 Fixes #11 and #15. Remove all references to webpack's style-loader and css-loader. Remove extract-text-webpack-plugin.
1 parent 0d30aa5 commit 79e674d

File tree

6 files changed

+47
-50
lines changed

6 files changed

+47
-50
lines changed

examples/babel-plugin-react-hot/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ module.exports = {
3333
test: /\.js?$/,
3434
exclude: /node_modules/,
3535
loader: 'babel'
36-
}, {
37-
test: /\.css?$/,
38-
loader: 'style-loader!css-loader?sourceMap&modules&localIdentName=[path][name]---[local]---[hash:base64:5]'
3936
}
4037
]
4138
}

examples/react-hot-loader-example/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
"devDependencies": {
2525
"babel-core": "^5.6.18",
2626
"babel-loader": "^5.1.4",
27-
"css-loader": "^0.15.5",
28-
"csslint": "^0.10.0",
29-
"csslint-loader": "^0.2.0",
3027
"node-libs-browser": "^0.5.2",
3128
"react-hot-loader": "davidpfahler/react-hot-loader#error-reporter",
3229
"webpack": "^1.9.11",

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"build:prod": "NODE_ENV=production webpack src/index.js dist/redbox.min.js",
1212
"build:test": "TEST=true webpack src/index.js tmp/redbox.js",
1313
"build": "npm run build:dev && npm run build:prod",
14-
"lint": "standard ./src && csslint ./src/redbox.css --quiet",
14+
"lint": "standard ./src",
1515
"prepublish": "npm run clean && npm run build",
1616
"test": "npm run lint -s && npm run build:test -s && babel-node ./tests | tap-spec",
1717
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
@@ -37,21 +37,16 @@
3737
"babel-core": "^5.6.18",
3838
"babel-eslint": "^3.1.15",
3939
"babel-loader": "^5.1.4",
40-
"css-loader": "^0.15.5",
41-
"csslint": "^0.10.0",
42-
"csslint-loader": "^0.2.0",
43-
"extract-text-webpack-plugin": "^0.8.2",
4440
"rimraf": "^2.3.4",
4541
"standard": "^5.0.0-2",
46-
"style-loader": "^0.12.3",
4742
"tap-spec": "^4.0.2",
4843
"tape": "^4.0.1",
4944
"webpack": "^1.9.6",
5045
"webpack-dev-server": "^1.8.2",
5146
"semantic-release": "^4.0.0"
5247
},
5348
"peerDependencies": {
54-
"react": ">=0.13.2 || ^0.14.0-beta3"
49+
"react": ">=0.13.2 || ^0.14.0-rc1"
5550
},
5651
"dependencies": {
5752
"error-stack-parser": "^1.2.0"

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {Component, PropTypes} from 'react'
2-
import {redbox, message, stack, frame, file} from './redbox.css'
2+
import {redbox, message, stack, frame, file, linkToFile} from './style.js'
33
import ErrorStackParser from 'error-stack-parser'
44

55
export default class RedBox extends Component {
@@ -12,18 +12,18 @@ export default class RedBox extends Component {
1212
const frames = ErrorStackParser.parse(error).map((f, index) => {
1313
const link = `${f.fileName}:${f.lineNumber}:${f.columnNumber}`
1414
return (
15-
<div className={frame} key={index}>
15+
<div style={frame} key={index}>
1616
<div>{f.functionName}</div>
17-
<div className={file}>
18-
<a href={link}>{link}</a>
17+
<div style={file}>
18+
<a href={link} style={linkToFile}>{link}</a>
1919
</div>
2020
</div>
2121
)
2222
})
2323
return (
24-
<div className={redbox}>
25-
<div className={message}>{error.name}: {error.message}</div>
26-
<div className={stack}>{frames}</div>
24+
<div style={redbox}>
25+
<div style={message}>{error.name}: {error.message}</div>
26+
<div style={stack}>{frames}</div>
2727
</div>
2828
)
2929
}

src/style.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export default {
2+
redbox: {
3+
boxSizing: 'border-box',
4+
fontFamily: 'sans-serif',
5+
fontSize: '1em',
6+
position: 'fixed',
7+
padding: 10,
8+
top: 0,
9+
left: 0,
10+
bottom: 0,
11+
right: 0,
12+
width: '100%',
13+
background: 'rgb(204, 0, 0)',
14+
color: 'white',
15+
zIndex: 9999
16+
},
17+
message: {
18+
fontWeight: 'bold'
19+
},
20+
stack: {
21+
fontFamily: 'monospace',
22+
marginTop: '2em'
23+
},
24+
frame: {
25+
marginTop: '1em'
26+
},
27+
file: {
28+
fontSize: '0.8em',
29+
color: 'rgba(255, 255, 255, 0.7)'
30+
},
31+
linkToFile: {
32+
textDecoration: 'none',
33+
color: 'rgba(255, 255, 255, 0.7)'
34+
}
35+
};

webpack.config.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
// imports
44
var webpack = require('webpack')
5-
var ExtractTextPlugin = require('extract-text-webpack-plugin')
65

76
// configurations
8-
var TEST, PROD
9-
if (process.env.TEST) {
10-
TEST = true
11-
} else if (process.env.NODE_ENV === 'production') {
7+
var PROD
8+
if (process.env.NODE_ENV === 'production') {
129
PROD = true
1310
}
1411

@@ -22,11 +19,6 @@ var plugins = [
2219

2320
let config = {
2421
module: {
25-
preLoaders: [{
26-
test: /\.css?$/,
27-
loader: 'csslint',
28-
include: /stylesheets/
29-
}],
3022
loaders: [{
3123
test: /\.js$/,
3224
loaders: ['babel-loader'],
@@ -46,20 +38,7 @@ let config = {
4638
}
4739
}
4840

49-
// Mutates config to use the ExtractTextPlugin to extract
50-
// css instead of inlining it.
51-
function extractCSS (config) {
52-
config.plugins.push(new ExtractTextPlugin('redbox.css', {allChunks: true}))
53-
54-
config.module.loaders.push({
55-
test: /\.css?$/,
56-
loader: ExtractTextPlugin.extract('css-loader?modules&localIdentName=[hash:base64:5]')
57-
})
58-
}
59-
60-
if (TEST) {
61-
extractCSS(config)
62-
} else if (PROD) {
41+
if (PROD) {
6342
config.plugins.push(
6443
new webpack.optimize.UglifyJsPlugin({
6544
compressor: {
@@ -68,12 +47,6 @@ if (TEST) {
6847
}
6948
})
7049
)
71-
extractCSS(config)
72-
} else {
73-
config.module.loaders.push({
74-
test: /\.css?$/,
75-
loader: 'style-loader!css-loader?sourceMap&modules&localIdentName=[path][name]---[local]---[hash:base64:5]'
76-
})
7750
}
7851

7952
module.exports = config

0 commit comments

Comments
 (0)