Skip to content

Commit f05cba5

Browse files
authored
Use /static paths for assets (#278)
* Use /static paths for assets * Fix e2e test
1 parent d2baa3c commit f05cba5

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

config/webpack.config.dev.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var paths = require('./paths');
1616
module.exports = {
1717
devtool: 'eval',
1818
entry: [
19-
require.resolve('webpack-dev-server/client'),
19+
require.resolve('webpack-dev-server/client') + '?/',
2020
require.resolve('webpack/hot/dev-server'),
2121
require.resolve('./polyfills'),
2222
path.join(paths.appSrc, 'index')
@@ -25,7 +25,7 @@ module.exports = {
2525
// Next line is not used in dev but WebpackDevServer crashes without it:
2626
path: paths.appBuild,
2727
pathinfo: true,
28-
filename: 'bundle.js',
28+
filename: 'static/js/bundle.js',
2929
publicPath: '/'
3030
},
3131
resolve: {
@@ -75,11 +75,18 @@ module.exports = {
7575
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
7676
include: [paths.appSrc, paths.appNodeModules],
7777
loader: 'file',
78+
query: {
79+
name: 'static/media/[name].[ext]'
80+
}
7881
},
7982
{
8083
test: /\.(mp4|webm)$/,
8184
include: [paths.appSrc, paths.appNodeModules],
82-
loader: 'url?limit=10000'
85+
loader: 'url',
86+
query: {
87+
limit: 10000,
88+
name: 'static/media/[name].[ext]'
89+
}
8390
}
8491
]
8592
},

config/webpack.config.prod.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ module.exports = {
3131
],
3232
output: {
3333
path: paths.appBuild,
34-
filename: '[name].[chunkhash:8].js',
35-
chunkFilename: '[name].[chunkhash:8].chunk.js',
34+
filename: 'static/js/[name].[chunkhash:8].js',
35+
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
3636
publicPath: publicPath
3737
},
3838
resolve: {
@@ -86,13 +86,17 @@ module.exports = {
8686
include: [paths.appSrc, paths.appNodeModules],
8787
loader: 'file',
8888
query: {
89-
name: '[name].[hash:8].[ext]'
89+
name: 'static/media/[name].[hash:8].[ext]'
9090
}
9191
},
9292
{
9393
test: /\.(mp4|webm)$/,
9494
include: [paths.appSrc, paths.appNodeModules],
95-
loader: 'url?limit=10000'
95+
loader: 'url',
96+
query: {
97+
limit: 10000,
98+
name: 'static/media/[name].[hash:8].[ext]'
99+
}
96100
}
97101
]
98102
},
@@ -139,6 +143,6 @@ module.exports = {
139143
screw_ie8: true
140144
}
141145
}),
142-
new ExtractTextPlugin('[name].[contenthash:8].css')
146+
new ExtractTextPlugin('static/css/[name].[contenthash:8].css')
143147
]
144148
};

scripts/build.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,28 @@ webpack(config).run(function(err, stats) {
4040
.filter(asset => /\.(js|css)$/.test(asset.name))
4141
.map(asset => {
4242
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
43+
var size = gzipSize(fileContents);
4344
return {
44-
name: asset.name,
45-
size: gzipSize(fileContents)
45+
folder: path.join('build', path.dirname(asset.name)),
46+
name: path.basename(asset.name),
47+
size: size,
48+
sizeLabel: filesize(size)
4649
};
4750
});
4851
assets.sort((a, b) => b.size - a.size);
52+
53+
var longestSizeLabelLength = Math.max.apply(null,
54+
assets.map(a => a.sizeLabel.length)
55+
);
4956
assets.forEach(asset => {
57+
var sizeLabel = asset.sizeLabel;
58+
if (sizeLabel.length < longestSizeLabelLength) {
59+
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLabel.length);
60+
sizeLabel += rightPadding;
61+
}
5062
console.log(
51-
' ' + chalk.dim('build' + path.sep) + chalk.cyan(asset.name) + ': ' +
52-
chalk.green(filesize(asset.size))
63+
' ' + chalk.green(sizeLabel) +
64+
' ' + chalk.dim(asset.folder + path.sep) + chalk.cyan(asset.name)
5365
);
5466
});
5567
console.log();

tasks/e2e.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ npm run build
6161

6262
# Check for expected output
6363
test -e build/*.html
64-
test -e build/*.js
64+
test -e build/static/js/*.js
65+
test -e build/static/css/*.css
66+
test -e build/static/media/*.svg
6567

6668
# Pack CLI
6769
cd global-cli
@@ -84,7 +86,9 @@ npm run build
8486

8587
# Check for expected output
8688
test -e build/*.html
87-
test -e build/*.js
89+
test -e build/static/js/*.js
90+
test -e build/static/css/*.css
91+
test -e build/static/media/*.svg
8892

8993
# Test the server
9094
npm start -- --smoke-test
@@ -95,7 +99,9 @@ npm run build
9599

96100
# Check for expected output
97101
test -e build/*.html
98-
test -e build/*.js
102+
test -e build/static/js/*.js
103+
test -e build/static/css/*.css
104+
test -e build/static/media/*.svg
99105

100106
# Test the server
101107
npm start -- --smoke-test

0 commit comments

Comments
 (0)