Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use /static paths for assets #278

Merged
merged 2 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var paths = require('./paths');
module.exports = {
devtool: 'eval',
entry: [
require.resolve('webpack-dev-server/client'),
require.resolve('webpack-dev-server/client') + '?/',
require.resolve('webpack/hot/dev-server'),
require.resolve('./polyfills'),
path.join(paths.appSrc, 'index')
Expand All @@ -25,7 +25,7 @@ module.exports = {
// Next line is not used in dev but WebpackDevServer crashes without it:
path: paths.appBuild,
pathinfo: true,
filename: 'bundle.js',
filename: 'static/js/bundle.js',
publicPath: '/'
},
resolve: {
Expand Down Expand Up @@ -75,11 +75,18 @@ module.exports = {
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
include: [paths.appSrc, paths.appNodeModules],
loader: 'file',
query: {
name: 'static/media/[name].[ext]'
}
},
{
test: /\.(mp4|webm)$/,
include: [paths.appSrc, paths.appNodeModules],
loader: 'url?limit=10000'
loader: 'url',
query: {
limit: 10000,
name: 'static/media/[name].[ext]'
}
}
]
},
Expand Down
14 changes: 9 additions & 5 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = {
],
output: {
path: paths.appBuild,
filename: '[name].[chunkhash:8].js',
chunkFilename: '[name].[chunkhash:8].chunk.js',
filename: 'static/js/[name].[chunkhash:8].js',
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
publicPath: publicPath
},
resolve: {
Expand Down Expand Up @@ -86,13 +86,17 @@ module.exports = {
include: [paths.appSrc, paths.appNodeModules],
loader: 'file',
query: {
name: '[name].[hash:8].[ext]'
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
test: /\.(mp4|webm)$/,
include: [paths.appSrc, paths.appNodeModules],
loader: 'url?limit=10000'
loader: 'url',
query: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
}
]
},
Expand Down Expand Up @@ -139,6 +143,6 @@ module.exports = {
screw_ie8: true
}
}),
new ExtractTextPlugin('[name].[contenthash:8].css')
new ExtractTextPlugin('static/css/[name].[contenthash:8].css')
]
};
20 changes: 16 additions & 4 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,28 @@ webpack(config).run(function(err, stats) {
.filter(asset => /\.(js|css)$/.test(asset.name))
.map(asset => {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
var size = gzipSize(fileContents);
return {
name: asset.name,
size: gzipSize(fileContents)
folder: path.join('build', path.dirname(asset.name)),
name: path.basename(asset.name),
size: size,
sizeLabel: filesize(size)
};
});
assets.sort((a, b) => b.size - a.size);

var longestSizeLabelLength = Math.max.apply(null,
assets.map(a => a.sizeLabel.length)
);
assets.forEach(asset => {
var sizeLabel = asset.sizeLabel;
if (sizeLabel.length < longestSizeLabelLength) {
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLabel.length);
sizeLabel += rightPadding;
}
console.log(
' ' + chalk.dim('build' + path.sep) + chalk.cyan(asset.name) + ': ' +
chalk.green(filesize(asset.size))
' ' + chalk.green(sizeLabel) +
' ' + chalk.dim(asset.folder + path.sep) + chalk.cyan(asset.name)
);
});
console.log();
Expand Down
12 changes: 9 additions & 3 deletions tasks/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ npm run build

# Check for expected output
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
cd global-cli
Expand All @@ -84,7 +86,9 @@ npm run build

# Check for expected output
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
npm start -- --smoke-test
Expand All @@ -95,7 +99,9 @@ npm run build

# Check for expected output
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
npm start -- --smoke-test
Expand Down