Skip to content

Commit b3a99b8

Browse files
committed
Update dependences and build process to inline CSS & files when running as a dev server
1 parent 55f3386 commit b3a99b8

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

.eslintrc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
{
22
"parser": "babel-eslint",
3+
"extends": "eslint:recommended",
4+
"env": {
5+
"browser": true,
6+
"mocha": true,
7+
"es6": true
8+
},
9+
"parserOptions": {
10+
"ecmaFeatures": {
11+
"modules": true,
12+
"jsx": true
13+
}
14+
},
15+
"globals": {},
316
"rules": {
17+
"no-empty": 0,
18+
"no-console": 0,
19+
"no-unused-vars": [0, { "varsIgnorePattern": "^h$" }],
20+
"no-cond-assign": 1,
421
"semi": 2,
522
"camelcase": 0,
623
"comma-style": 2,
@@ -13,20 +30,19 @@
1330
"no-implied-eval": 2,
1431
"no-new-func": 2,
1532
"guard-for-in": 2,
16-
"eqeqeq": 2,
33+
"eqeqeq": 1,
1734
"no-else-return": 2,
1835
"no-redeclare": 2,
1936
"no-dupe-keys": 2,
2037
"radix": 2,
2138
"strict": [2, "never"],
2239
"no-shadow": 0,
23-
"callback-return": [1, ["callback", "cb", "next", "done"]],
2440
"no-delete-var": 2,
2541
"no-undef-init": 2,
2642
"no-shadow-restricted-names": 2,
2743
"handle-callback-err": 0,
2844
"no-lonely-if": 2,
29-
"space-return-throw-case": 2,
45+
"keyword-spacing": 2,
3046
"constructor-super": 2,
3147
"no-this-before-super": 2,
3248
"no-dupe-class-members": 2,

package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,42 @@
2020
"devDependencies": {
2121
"autoprefixer": "^6.3.3",
2222
"babel": "^6.5.2",
23-
"babel-core": "^6.5.2",
23+
"babel-core": "^6.7.2",
2424
"babel-eslint": "^5.0.0",
25-
"babel-loader": "^6.2.3",
25+
"babel-loader": "^6.2.4",
2626
"babel-plugin-transform-decorators-legacy": "^1.3.4",
27-
"babel-plugin-transform-react-jsx": "^6.5.2",
28-
"babel-preset-es2015": "^6.5.0",
27+
"babel-plugin-transform-react-jsx": "^6.6.5",
28+
"babel-preset-es2015": "^6.6.0",
2929
"babel-preset-es2015-minimal": "^1.0.0",
3030
"babel-preset-stage-0": "^6.5.0",
31-
"babel-register": "^6.5.2",
32-
"babel-runtime": "^6.5.0",
31+
"babel-register": "^6.7.2",
32+
"babel-runtime": "^6.6.1",
3333
"chai": "^3.5.0",
34-
"core-js": "^2.1.0",
34+
"core-js": "^2.1.5",
3535
"css-loader": "^0.23.1",
36-
"eslint": "^1.10.3",
36+
"eslint": "^2.2.0",
3737
"extract-text-webpack-plugin": "^1.0.1",
3838
"file-loader": "^0.8.5",
3939
"html-webpack-plugin": "^1.7.0",
4040
"json-loader": "^0.5.4",
41-
"less": "^2.6.0",
41+
"less": "^2.6.1",
4242
"less-loader": "^2.2.2",
4343
"ncp": "^2.0.0",
44-
"npm-run-all": "^1.5.1",
45-
"postcss-loader": "^0.8.1",
44+
"npm-run-all": "^1.5.3",
45+
"postcss-loader": "^0.8.2",
4646
"raw-loader": "^0.5.1",
4747
"source-map-loader": "^0.1.5",
48-
"superstatic": "^4.0.1",
48+
"style-loader": "^0.13.0",
49+
"superstatic": "^4.0.2",
4950
"url-loader": "^0.5.7",
5051
"webpack": "^1.12.13",
5152
"webpack-dev-server": "^1.14.1"
5253
},
5354
"dependencies": {
5455
"decko": "^1.1.3",
55-
"preact": "^3.4.0",
56-
"preact-compat": "^0.7.1",
57-
"preact-router": "^1.2.3",
56+
"preact": "^4.3.2",
57+
"preact-compat": "^1.6.1",
58+
"preact-router": "^1.3.0",
5859
"proptypes": "^0.14.3"
5960
}
6061
}

webpack.config.babel.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin';
33
import HtmlWebpackPlugin from 'html-webpack-plugin';
44
import autoprefixer from 'autoprefixer';
55

6+
/*global process,module,__dirname*/
7+
68
const ENV = process.env.NODE_ENV || 'development';
79

10+
const CSS_MAPS = ENV!=='production';
11+
812
module.exports = {
9-
entry: './src/index.js',
13+
context: __dirname+'/src',
14+
entry: './index.js',
1015

1116
output: {
12-
path: './build',
17+
path: __dirname+'/build',
1318
publicPath: '/',
1419
filename: 'bundle.js'
1520
},
@@ -22,7 +27,7 @@ module.exports = {
2227
'node_modules'
2328
],
2429
alias: {
25-
components: `${__dirname}/src/components`, // used for tests
30+
components: `${__dirname}/src/components`,
2631
style: `${__dirname}/src/style`,
2732
'react': 'preact-compat',
2833
'react-dom': 'preact-compat'
@@ -46,16 +51,16 @@ module.exports = {
4651
{
4752
test: /\.(less|css)$/,
4853
include: /src\/components\//,
49-
loader: ExtractTextPlugin.extract([
50-
`css?sourceMap&modules&importLoaders=1&localIdentName=[local]${process.env.CSS_MODULES_IDENT || '_[hash:base64:5]'}`,
54+
loader: ExtractTextPlugin.extract('style', [
55+
`css?sourceMap=${CSS_MAPS}&modules&importLoaders=1&localIdentName=[local]${process.env.CSS_MODULES_IDENT || '_[hash:base64:5]'}`,
5156
'postcss',
52-
'less?sourceMap'
57+
`less?sourceMap=${CSS_MAPS}`
5358
].join('!'))
5459
},
5560
{
5661
test: /\.(less|css)$/,
5762
exclude: /src\/components\//,
58-
loader: ExtractTextPlugin.extract('css?sourceMap!postcss!less?sourceMap')
63+
loader: ExtractTextPlugin.extract('style', `css?sourceMap=${CSS_MAPS}!postcss!less?sourceMap=${CSS_MAPS}`)
5964
},
6065
{
6166
test: /\.json$/,
@@ -66,8 +71,8 @@ module.exports = {
6671
loader: 'raw'
6772
},
6873
{
69-
test: /\.(svg|woff|ttf|eot)(\?.*)?$/i,
70-
loader: 'file-loader?name=assets/fonts/[name]_[hash:base64:5].[ext]'
74+
test: /\.(svg|woff2?|ttf|eot|jpe?g|png|gif)(\?.*)?$/i,
75+
loader: process.env.NODE_ENV==='production' ? 'file?name=[path][name]_[hash:base64:5].[ext]' : 'url'
7176
}
7277
]
7378
},
@@ -78,10 +83,13 @@ module.exports = {
7883

7984
plugins: ([
8085
new webpack.NoErrorsPlugin(),
81-
new ExtractTextPlugin('style.css', { allChunks: true }),
86+
new ExtractTextPlugin('style.css', {
87+
allChunks: true,
88+
disable: ENV!=='production'
89+
}),
8290
new webpack.optimize.DedupePlugin(),
8391
new webpack.DefinePlugin({
84-
'process.env.NODE_ENV': JSON.stringify(ENV)
92+
'process.env': JSON.stringify({ NODE_ENV: ENV })
8593
}),
8694
new HtmlWebpackPlugin({
8795
template: 'src/index.html',

0 commit comments

Comments
 (0)