Skip to content

Commit

Permalink
webpack config for dev does not hash the assets
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Aug 24, 2017
1 parent 6d7f345 commit 96e7c45
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 109 deletions.
2 changes: 1 addition & 1 deletion app/api/config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default {
demo: 'mongodb://localhost/uwazi_demo',
development: DBHOST ? `mongodb://${DBHOST}/${DATABASE_NAME}` : 'mongodb://localhost/uwazi_development',
testing: DBHOST ? `mongodb://${DBHOST}/${DATABASE_NAME}` : 'mongodb://localhost/uwazi_testing',
production: `mongodb://localhost/${DATABASE_NAME}`
production: DBHOST ? `mongodb://${DBHOST}/${DATABASE_NAME}` : 'mongodb://localhost/uwazi_development'
};
2 changes: 1 addition & 1 deletion app/api/config/elasticIndexes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const INDEX_NAME = process.env.INDEX_NAME;

export default {
production: INDEX_NAME ? INDEX_NAME : 'uwazi',
production: INDEX_NAME ? INDEX_NAME : 'uwazi_development',
testing: INDEX_NAME ? INDEX_NAME : 'testing',
development: INDEX_NAME ? INDEX_NAME : 'uwazi_development',
demo: INDEX_NAME ? INDEX_NAME : 'uwazi_demo'
Expand Down
2 changes: 1 addition & 1 deletion app/api/config/ports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const PORT = process.env.PORT;
export default {
production: PORT ? PORT : 3001,
production: PORT ? PORT : 3000,
development: PORT ? PORT : 3000,
demo: PORT ? PORT : 4000
};
8 changes: 7 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ var error_handling_middleware = require('./app/api/utils/error_handling_middlewa
app.use(error_handling_middleware);
app.use(compression());
var oneYear = 31557600;
app.use(express.static(path.resolve(__dirname, 'dist'), {maxage: oneYear}));

var maxage = 0;
if (app.get('env') === 'production') {
maxage = oneYear;
}

app.use(express.static(path.resolve(__dirname, 'dist'), {maxage: maxage}));
app.use('/uploaded_documents', express.static(path.resolve(__dirname, 'uploaded_documents')));
app.use('/public', express.static(path.resolve(__dirname, 'public')));
app.use('/flag-images', express.static(path.resolve(__dirname, 'node_modules/react-flags/vendor/flags')));
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
'use strict';

var config = require('./webpack/config');
var config = require('./webpack/config')();

config.context = __dirname;

Expand Down
3 changes: 2 additions & 1 deletion webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var webpack = require('webpack');
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
var CompressionPlugin = require('compression-webpack-plugin');

var config = require('./webpack/config');
var production = true;
var config = require('./webpack/config')(production);

config.devtool = 'cheap-module-source-map';
config.context = __dirname;
Expand Down
217 changes: 114 additions & 103 deletions webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,111 +8,122 @@ var CleanPlugin = require('./CleanPlugin');

var rootPath = __dirname + '/../';

const CoreCss = new ExtractTextPlugin('styles.[contenthash].css');
var AssetsPlugin = require('assets-webpack-plugin')
var assetsPluginInstance = new AssetsPlugin({path: path.join(rootPath + '/dist/')})

module.exports = {
context: rootPath,
devtool: '#eval-source-map',
entry: {
main: path.join(rootPath, 'app/react/index.js'),
nprogress: path.join(rootPath, 'node_modules/nprogress/nprogress.js'),
'pdf.worker': path.join(rootPath, 'node_modules/pdfjs-dist/build/pdf.worker.entry'),
},
output: {
path: path.join(rootPath, '/dist/'),
publicPath: '/',
filename: '[name].[chunkhash].js'
},
resolveLoader: {
modules: ['node_modules', __dirname + '/webpackLoaders'],
extensions: ['.js', '.json'],
mainFields: ['loader', 'main']
},
module: {
rules: [
{
test: /world-countries/,
loader: 'country-loader'
},
{
test: /\.js$/,
loader: 'babel-loader?cacheDirectory',
include: path.join(rootPath, 'app'),
exclude: /node_modules/
},
{
test: /\.scss$/,
loader: CoreCss.extract({
fallback: 'style-loader',
use: 'css-loader?sourceMap!sass-loader?outputStyle=expanded&sourceMap=true&sourceMapContents=true'
}),
include: [
path.join(rootPath, 'app'),
path.join(rootPath, 'node_modules/react-widgets/lib/scss/')
]
},
{
test: /\.css$/,
loader: CoreCss.extract({
fallback: 'style-loader',
use: 'css-loader?sourceMap'
}),
include: [
path.join(rootPath, 'app'),
path.join(rootPath, 'node_modules/react-datepicker/dist/'),
path.join(rootPath, 'node_modules/bootstrap/dist/'),
path.join(rootPath, 'node_modules/nprogress/'),
path.join(rootPath, 'node_modules/font-awesome/css/'),
path.join(rootPath, 'node_modules/pdfjs-dist/web'),
]
},
{
test: /\.(jpe?g|png|eot|woff|woff2|ttf|gif|svg)(\?.*)?$/i,
loaders: ['url-loader', 'img-loader'],
include: [
path.join(rootPath, 'public'),
path.join(rootPath, 'app'),
path.join(rootPath, 'node_modules/react-widgets/lib/fonts/'),
path.join(rootPath, 'node_modules/font-awesome/fonts/'),
path.join(rootPath, 'node_modules/react-widgets/lib/img/'),
path.join(rootPath, 'node_modules/pdfjs-dist/web/images/'),
path.join(rootPath, 'node_modules/pdfjs-dist/web/images/'),
path.join(rootPath, 'node_modules/bootstrap/dist/fonts/')
]
},
{
test:/\.json$/i,
loaders: ['json-loader'],
include: [
path.join(rootPath, 'app')
]
}
]
},
plugins: [
new CleanPlugin(__dirname + '/../dist/'),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ["main"],
minChunks: ({ resource }) => {
if (/pdfjs/.test(resource)) {
return false;
}
module.exports = function(production) {
var stylesName = 'styles.css';
var jsChunkHashName = '';

if (production) {
stylesName = 'styles.[contenthash].css';
jsChunkHashName = '.[chunkhash]';
}

if (/.js$/.test(resource)) {
return /node_modules/.test(resource)
const CoreCss = new ExtractTextPlugin(stylesName);
return {
context: rootPath,
devtool: '#eval-source-map',
entry: {
main: path.join(rootPath, 'app/react/index.js'),
nprogress: path.join(rootPath, 'node_modules/nprogress/nprogress.js'),
'pdf.worker': path.join(rootPath, 'node_modules/pdfjs-dist/build/pdf.worker.entry'),
},
output: {
path: path.join(rootPath, '/dist/'),
publicPath: '/',
filename: '[name]'+jsChunkHashName+'.js'
},
resolveLoader: {
modules: ['node_modules', __dirname + '/webpackLoaders'],
extensions: ['.js', '.json'],
mainFields: ['loader', 'main']
},
module: {
rules: [
{
test: /world-countries/,
loader: 'country-loader'
},
{
test: /\.js$/,
loader: 'babel-loader?cacheDirectory',
include: path.join(rootPath, 'app'),
exclude: /node_modules/
},
{
test: /\.scss$/,
loader: CoreCss.extract({
fallback: 'style-loader',
use: 'css-loader?sourceMap!sass-loader?outputStyle=expanded&sourceMap=true&sourceMapContents=true'
}),
include: [
path.join(rootPath, 'app'),
path.join(rootPath, 'node_modules/react-widgets/lib/scss/')
]
},
{
test: /\.css$/,
loader: CoreCss.extract({
fallback: 'style-loader',
use: 'css-loader?sourceMap'
}),
include: [
path.join(rootPath, 'app'),
path.join(rootPath, 'node_modules/react-datepicker/dist/'),
path.join(rootPath, 'node_modules/bootstrap/dist/'),
path.join(rootPath, 'node_modules/nprogress/'),
path.join(rootPath, 'node_modules/font-awesome/css/'),
path.join(rootPath, 'node_modules/pdfjs-dist/web'),
]
},
{
test: /\.(jpe?g|png|eot|woff|woff2|ttf|gif|svg)(\?.*)?$/i,
loaders: ['url-loader', 'img-loader'],
include: [
path.join(rootPath, 'public'),
path.join(rootPath, 'app'),
path.join(rootPath, 'node_modules/react-widgets/lib/fonts/'),
path.join(rootPath, 'node_modules/font-awesome/fonts/'),
path.join(rootPath, 'node_modules/react-widgets/lib/img/'),
path.join(rootPath, 'node_modules/pdfjs-dist/web/images/'),
path.join(rootPath, 'node_modules/pdfjs-dist/web/images/'),
path.join(rootPath, 'node_modules/bootstrap/dist/fonts/')
]
},
{
test:/\.json$/i,
loaders: ['json-loader'],
include: [
path.join(rootPath, 'app')
]
}
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
chunks: ["main", "vendor", "nprogress", "pdf.worker"],
minChunks: Infinity
}),
CoreCss,
new webpack.optimize.ModuleConcatenationPlugin(),
assetsPluginInstance
]
};
]
},
plugins: [
new CleanPlugin(__dirname + '/../dist/'),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ["main"],
minChunks: ({ resource }) => {
if (/pdfjs/.test(resource)) {
return false;
}

if (/.js$/.test(resource)) {
return /node_modules/.test(resource)
}
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
chunks: ["main", "vendor", "nprogress", "pdf.worker"],
minChunks: Infinity
}),
CoreCss,
new webpack.optimize.ModuleConcatenationPlugin(),
assetsPluginInstance
]
};
}

0 comments on commit 96e7c45

Please sign in to comment.