Skip to content

Commit a20cd92

Browse files
committed
config url-loader
1 parent 5c6cffa commit a20cd92

File tree

17 files changed

+55
-87
lines changed

17 files changed

+55
-87
lines changed

.flowconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ module.name_mapper='\$styles' -> '<PROJECT_ROOT>/src/styles'
1212
module.name_mapper='\$containers' -> '<PROJECT_ROOT>/src/containers'
1313
module.name_mapper='\$reducers' -> '<PROJECT_ROOT>/src/reducers'
1414
module.name_mapper='\$layouts' -> '<PROJECT_ROOT>/src/layouts'
15+
module.name_mapper='\$images' -> '<PROJECT_ROOT>/src/assets/images'
16+
module.name_mapper='\$fonts' -> '<PROJECT_ROOT>/src/assets/fonts'
1517
module.file_ext=.css
1618
module.file_ext=.less

bin/compile.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const debug = require('debug')('app:bin:compile');
2-
const fs = require('fs-extra');
32
const chalk = require('chalk');
43
const compiler = require('../build/compiler');
54
const env = require('../build/base-config/environment');
6-
const paths = require('../build/base-config/path');
75
const webpackConfig = require('../build/webpack-config');
86

97
const startCompile = () => {
@@ -15,7 +13,6 @@ const startCompile = () => {
1513
throw new Error('Production not allow warnig, exit .');
1614
}
1715
debug('Copying static assets to dist folder.');
18-
fs.copySync(paths.public(), paths.dist());
1916
return stats;
2017
})
2118
.then(stats => {

build/base-config/configs.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,35 @@ module.exports = {
22
development: {
33
performance: {
44
hints: false,
5-
maxAssetSize: 2000000 // 2.5M
6-
}
5+
maxAssetSize: 2000000, // 2.5M
6+
},
77
},
88
production: {
99
performance: {
1010
hints: 'error',
11-
maxEntrypointSize: 1500000 // 1.5M
11+
maxEntrypointSize: 1500000, // 1.5M
1212
},
1313
stats: {
1414
chunkModules: false,
1515
colors: true,
1616
chunks: false,
17-
children: false
18-
}
17+
children: false,
18+
},
1919
},
2020
defaults: {
2121
stats: {
2222
chunkModules: false,
2323
colors: true,
24-
chunks: false
25-
},
26-
performance: {
27-
hints: 'warning'
24+
chunks: false,
2825
},
29-
vendors: [
30-
'react',
31-
'react-redux',
32-
'react-router-dom',
33-
'redux',
34-
'react-dom'
35-
],
26+
hash: '[hash:8]',
27+
vendors: ['react', 'react-redux', 'react-router-dom', 'redux', 'react-dom'],
3628
postcss: [
3729
require('autoprefixer')({
3830
add: true,
3931
remove: true,
40-
browsers: ['last 2 versions']
41-
})
42-
]
43-
}
32+
browsers: ['last 2 versions'],
33+
}),
34+
],
35+
},
4436
};

build/webpack-config/alias.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = paths => ({
77
'$components': paths.src('components'),
88
'$containers': paths.src('containers'),
99
'$styles': paths.src('styles'),
10+
'$images': paths.src('assets/images'),
11+
'$fonts': paths.src('assets/fonts'),
1012
'$reducers': paths.src('reducers'),
1113
'$layouts': paths.src('layouts'),
1214
'$flow-typed': paths.root('flow-typed'),

build/webpack-config/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = paths => {
2929
},
3030
devtool: isDev ? 'source-map' : false,
3131
output: {
32-
filename: '[name].[hash:8].js',
32+
filename: `[name].${envConfig.hash}.js`,
3333
path: paths.dist(),
3434
publicPath: '',
3535
},

build/webpack-config/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ const loaders = require('./loaders')();
77
const plugins = require('./plugins')(paths);
88

99
debug('Creating configuration.');
10-
module.exports = Object.assign({
11-
plugins,
12-
resolve: {
13-
alias
10+
module.exports = Object.assign(
11+
{
12+
plugins,
13+
resolve: {
14+
alias,
15+
},
16+
module: {
17+
loaders,
18+
},
1419
},
15-
module: {
16-
loaders
17-
}
18-
}, base);
20+
base
21+
);

build/webpack-config/loaders.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = () => {
1717
},
1818
{
1919
test: /\.css$/,
20+
include: /node_modules/,
2021
use: [
2122
{
2223
loader: 'style-loader',
@@ -25,16 +26,13 @@ module.exports = () => {
2526
loader: 'css-loader',
2627
options: {
2728
minimize: isProd,
28-
module: true,
2929
},
3030
},
31-
{
32-
loader: 'postcss-loader',
33-
},
3431
],
3532
},
3633
{
37-
test: /\.less$/,
34+
test: /\.(less|css)$/,
35+
exclude: /node_modules/,
3836
use: [
3937
{
4038
loader: 'style-loader',
@@ -44,6 +42,7 @@ module.exports = () => {
4442
options: {
4543
minimize: isProd,
4644
module: true,
45+
camelCase: true,
4746
},
4847
},
4948
{
@@ -64,6 +63,8 @@ module.exports = () => {
6463
loader: 'url-loader',
6564
options: {
6665
limit: 8192,
66+
useRelativePath: isProd,
67+
name: `images/[name].${env.config.hash}.[ext]`,
6768
},
6869
},
6970
],
@@ -73,9 +74,7 @@ module.exports = () => {
7374
debug('Apply ExtractTextPlugin to CSS loaders.');
7475
rules
7576
.filter(
76-
rule =>
77-
rule.use &&
78-
rule.use.find(loaderObj => /css/.test(loaderObj.loader.split('?')[0]))
77+
rule => rule.use && rule.use.find(loaderObj => /css/.test(loaderObj.loader.split('?')[0]))
7978
)
8079
.forEach(rule => {
8180
const first = rule.use[0];

build/webpack-config/plugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = paths => {
1414
new HtmlWebpackPlugin({
1515
template: paths.src('index.html'),
1616
hash: false,
17-
favicon: paths.src('static/favicon.ico'),
17+
favicon: paths.src('favicon.ico'),
1818
filename: 'index.html',
1919
inject: 'body',
2020
minify: {
@@ -40,7 +40,7 @@ module.exports = paths => {
4040
debug('Apply ExtractTextPlugin.');
4141
plugins.push(
4242
new ExtractTextPlugin({
43-
filename: '[name].[hash:8].css',
43+
filename: `[name].${env.config.hash}.css`,
4444
allChunks: true,
4545
})
4646
);

jsconfig.json

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,15 @@
33
"experimentalDecorators": true,
44
"baseUrl": "./",
55
"paths": {
6-
"$utils/*": [
7-
"src/utils/*"
8-
],
9-
"$components/*": [
10-
"src/components/*"
11-
],
12-
"$styles/*": [
13-
"src/styles/*"
14-
],
15-
"$containers/*": [
16-
"src/containers/*"
17-
],
18-
"$reducers/*": [
19-
"src/reducers/*"
20-
],
21-
"$layouts/*": [
22-
"src/layouts/*"
23-
],
24-
"$flow-typed/*": [
25-
"flow-typed/*"
26-
]
6+
"$utils/*": ["src/utils/*"],
7+
"$components/*": ["src/components/*"],
8+
"$styles/*": ["src/styles/*"],
9+
"$images/*": ["src/assets/images/*"],
10+
"$fonts/*": ["src/assets/fonts/*"],
11+
"$containers/*": ["src/containers/*"],
12+
"$reducers/*": ["src/reducers/*"],
13+
"$layouts/*": ["src/layouts/*"],
14+
"$flow-typed/*": ["flow-typed/*"]
2715
}
2816
}
2917
}

src/assets/fonts/.gitkeep

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

src/layouts/CoreLayout/CoreLayout.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import Header from '$components/Header';
33
import RouteWithSubRoutes from '$components/RouteWithSubRoutes';
44
import '$styles/core.less';
5-
import CoreLayoutModule from './CoreLayout.less';
5+
import { coreLayoutViewport } from './CoreLayout.less';
66
import Counter from '../Counter';
77
import type { StoreWithInjectAble, RouteProps } from '$self-define';
88
type props = {
@@ -15,10 +15,8 @@ const CoreLayout = (props: props) => {
1515
<div className="container text-center">
1616
<Counter />
1717
<Header />
18-
<div className={CoreLayoutModule['core-layout__viewport']}>
19-
{props
20-
.routes(props.store)
21-
.map((route, i) => <RouteWithSubRoutes key={i} {...route} />)}
18+
<div className={coreLayoutViewport}>
19+
{props.routes(props.store).map((route, i) => <RouteWithSubRoutes key={i} {...route} />)}
2220
</div>
2321
</div>
2422
);

src/routes/Home/components/HomeView.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
// @flow
22
import React from 'react';
3-
import HomeViewLess from './HomeView.less';
3+
import { magic } from './HomeView.less';
4+
import logo from '$images/magic.png';
45
export const HomeView = () => (
56
<div>
67
<h4>Welcome!</h4>
7-
<img
8-
alt="A magic!"
9-
className={HomeViewLess.magic}
10-
src="/images/magic.png"
11-
/>
8+
<img alt="A magic!" className={magic} src={logo} />
129
</div>
1310
);
1411

src/styles/base.less

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/styles/core.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@import 'base';
21
@import (less) '~normalize.css/normalize.css';
32

43
// Some best-practice CSS that's useful for most apps

src/styles/mixins.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*
2+
Mixins here;
3+
*/

0 commit comments

Comments
 (0)