Commit f05cba5e authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Use /static paths for assets (#278)

* Use /static paths for assets

* Fix e2e test
parent d2baa3c4
No related merge requests found
Showing with 44 additions and 15 deletions
+44 -15
...@@ -16,7 +16,7 @@ var paths = require('./paths'); ...@@ -16,7 +16,7 @@ var paths = require('./paths');
module.exports = { module.exports = {
devtool: 'eval', devtool: 'eval',
entry: [ entry: [
require.resolve('webpack-dev-server/client'), require.resolve('webpack-dev-server/client') + '?/',
require.resolve('webpack/hot/dev-server'), require.resolve('webpack/hot/dev-server'),
require.resolve('./polyfills'), require.resolve('./polyfills'),
path.join(paths.appSrc, 'index') path.join(paths.appSrc, 'index')
...@@ -25,7 +25,7 @@ module.exports = { ...@@ -25,7 +25,7 @@ module.exports = {
// Next line is not used in dev but WebpackDevServer crashes without it: // Next line is not used in dev but WebpackDevServer crashes without it:
path: paths.appBuild, path: paths.appBuild,
pathinfo: true, pathinfo: true,
filename: 'bundle.js', filename: 'static/js/bundle.js',
publicPath: '/' publicPath: '/'
}, },
resolve: { resolve: {
...@@ -75,11 +75,18 @@ module.exports = { ...@@ -75,11 +75,18 @@ module.exports = {
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/, test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
include: [paths.appSrc, paths.appNodeModules], include: [paths.appSrc, paths.appNodeModules],
loader: 'file', loader: 'file',
query: {
name: 'static/media/[name].[ext]'
}
}, },
{ {
test: /\.(mp4|webm)$/, test: /\.(mp4|webm)$/,
include: [paths.appSrc, paths.appNodeModules], include: [paths.appSrc, paths.appNodeModules],
loader: 'url?limit=10000' loader: 'url',
query: {
limit: 10000,
name: 'static/media/[name].[ext]'
}
} }
] ]
}, },
......
...@@ -31,8 +31,8 @@ module.exports = { ...@@ -31,8 +31,8 @@ module.exports = {
], ],
output: { output: {
path: paths.appBuild, path: paths.appBuild,
filename: '[name].[chunkhash:8].js', filename: 'static/js/[name].[chunkhash:8].js',
chunkFilename: '[name].[chunkhash:8].chunk.js', chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
publicPath: publicPath publicPath: publicPath
}, },
resolve: { resolve: {
...@@ -86,13 +86,17 @@ module.exports = { ...@@ -86,13 +86,17 @@ module.exports = {
include: [paths.appSrc, paths.appNodeModules], include: [paths.appSrc, paths.appNodeModules],
loader: 'file', loader: 'file',
query: { query: {
name: '[name].[hash:8].[ext]' name: 'static/media/[name].[hash:8].[ext]'
} }
}, },
{ {
test: /\.(mp4|webm)$/, test: /\.(mp4|webm)$/,
include: [paths.appSrc, paths.appNodeModules], include: [paths.appSrc, paths.appNodeModules],
loader: 'url?limit=10000' loader: 'url',
query: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
} }
] ]
}, },
...@@ -139,6 +143,6 @@ module.exports = { ...@@ -139,6 +143,6 @@ module.exports = {
screw_ie8: true screw_ie8: true
} }
}), }),
new ExtractTextPlugin('[name].[contenthash:8].css') new ExtractTextPlugin('static/css/[name].[contenthash:8].css')
] ]
}; };
...@@ -40,16 +40,28 @@ webpack(config).run(function(err, stats) { ...@@ -40,16 +40,28 @@ webpack(config).run(function(err, stats) {
.filter(asset => /\.(js|css)$/.test(asset.name)) .filter(asset => /\.(js|css)$/.test(asset.name))
.map(asset => { .map(asset => {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name); var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
var size = gzipSize(fileContents);
return { return {
name: asset.name, folder: path.join('build', path.dirname(asset.name)),
size: gzipSize(fileContents) name: path.basename(asset.name),
size: size,
sizeLabel: filesize(size)
}; };
}); });
assets.sort((a, b) => b.size - a.size); assets.sort((a, b) => b.size - a.size);
var longestSizeLabelLength = Math.max.apply(null,
assets.map(a => a.sizeLabel.length)
);
assets.forEach(asset => { assets.forEach(asset => {
var sizeLabel = asset.sizeLabel;
if (sizeLabel.length < longestSizeLabelLength) {
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLabel.length);
sizeLabel += rightPadding;
}
console.log( console.log(
' ' + chalk.dim('build' + path.sep) + chalk.cyan(asset.name) + ': ' + ' ' + chalk.green(sizeLabel) +
chalk.green(filesize(asset.size)) ' ' + chalk.dim(asset.folder + path.sep) + chalk.cyan(asset.name)
); );
}); });
console.log(); console.log();
......
...@@ -61,7 +61,9 @@ npm run build ...@@ -61,7 +61,9 @@ npm run build
# Check for expected output # Check for expected output
test -e build/*.html test -e build/*.html
test -e build/*.js test -e build/static/js/*.js
test -e build/static/css/*.css
test -e build/static/media/*.svg
# Pack CLI # Pack CLI
cd global-cli cd global-cli
...@@ -84,7 +86,9 @@ npm run build ...@@ -84,7 +86,9 @@ npm run build
# Check for expected output # Check for expected output
test -e build/*.html test -e build/*.html
test -e build/*.js test -e build/static/js/*.js
test -e build/static/css/*.css
test -e build/static/media/*.svg
# Test the server # Test the server
npm start -- --smoke-test npm start -- --smoke-test
...@@ -95,7 +99,9 @@ npm run build ...@@ -95,7 +99,9 @@ npm run build
# Check for expected output # Check for expected output
test -e build/*.html test -e build/*.html
test -e build/*.js test -e build/static/js/*.js
test -e build/static/css/*.css
test -e build/static/media/*.svg
# Test the server # Test the server
npm start -- --smoke-test npm start -- --smoke-test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment