Solved bug that caused main webpack assets incorrecly cached by browsers (Deployment should be tested)
This commit is contained in:
parent
8bc61ffc5a
commit
fd0d5b70be
|
@ -2,6 +2,7 @@ FROM node:8.9.4
|
||||||
|
|
||||||
COPY auth /app
|
COPY auth /app
|
||||||
COPY loopback /loopback
|
COPY loopback /loopback
|
||||||
|
COPY nginx/static/webpack-assets.json /loopback/server/
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body ng-app="vnAuth">
|
<body ng-app="vnAuth">
|
||||||
<vn-login></vn-login>
|
<vn-login></vn-login>
|
||||||
<script type="text/javascript"
|
<% for (let jsFile of assets('auth', ['vendor'])) { %>
|
||||||
src="/static/bundle.manifest.js">
|
<script type="text/javascript" src="<%= jsFile %>"></script>
|
||||||
</script>
|
<% } %>
|
||||||
<script type="text/javascript"
|
|
||||||
src="/static/bundle.vendor.js">
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript"
|
|
||||||
src="/static/bundle.auth.js">
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"compression": "^1.0.3",
|
"compression": "^1.0.3",
|
||||||
"cors": "^2.5.2",
|
"cors": "^2.5.2",
|
||||||
|
"fs-extra": "^5.0.0",
|
||||||
"helmet": "^1.3.0",
|
"helmet": "^1.3.0",
|
||||||
"i18n": "^0.8.3",
|
"i18n": "^0.8.3",
|
||||||
"loopback": "^3.14.0",
|
"loopback": "^3.14.0",
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
"loopback-connector-remote": "^3.1.1",
|
"loopback-connector-remote": "^3.1.1",
|
||||||
"loopback-context": "^3.3.0",
|
"loopback-context": "^3.3.0",
|
||||||
"md5": "^2.2.1",
|
"md5": "^2.2.1",
|
||||||
|
"require-yaml": "0.0.1",
|
||||||
"serve-favicon": "^2.0.1",
|
"serve-favicon": "^2.0.1",
|
||||||
"strong-error-handler": "^2.1.0"
|
"strong-error-handler": "^2.1.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
require('require-yaml');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the webpack asset filenames with its hash.
|
||||||
|
*
|
||||||
|
* @param {String} main The main asset name
|
||||||
|
* @param {Array} deps The main asset dependencies
|
||||||
|
* @return {Array} The assets filenames
|
||||||
|
*/
|
||||||
|
function assets(main, deps) {
|
||||||
|
let jsFiles;
|
||||||
|
let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
|
||||||
|
|
||||||
|
if (env === 'development') {
|
||||||
|
const wpConfig = require('../../../webpack.config.yml');
|
||||||
|
let publicPath = wpConfig.publicPath;
|
||||||
|
|
||||||
|
jsFiles = [`${publicPath}/manifest.js`];
|
||||||
|
|
||||||
|
for (let dep of deps)
|
||||||
|
jsFiles.push(`${publicPath}/${dep}.js`);
|
||||||
|
|
||||||
|
jsFiles.push(`${publicPath}/${main}.js`);
|
||||||
|
} else {
|
||||||
|
const wpAssets = require('./webpack-assets.json');
|
||||||
|
|
||||||
|
let jsFiles = [wpAssets.manifest.js];
|
||||||
|
|
||||||
|
for (let dep of deps)
|
||||||
|
jsFiles.push(wpAssets[dep].js);
|
||||||
|
|
||||||
|
jsFiles.push(wpAssets[main].js);
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = assets;
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
let loopback = require('loopback');
|
let loopback = require('loopback');
|
||||||
let boot = require('loopback-boot');
|
let boot = require('loopback-boot');
|
||||||
let path = require('path');
|
let fs = require('fs-extra');
|
||||||
let fs = require('fs');
|
|
||||||
let i18n = require('i18n');
|
let i18n = require('i18n');
|
||||||
|
let path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
loopback: loopback,
|
loopback: loopback,
|
||||||
|
@ -32,6 +32,11 @@ function vnBoot(app, rootDir, rootModule) {
|
||||||
app.set('view engine', 'ejs');
|
app.set('view engine', 'ejs');
|
||||||
app.set('views', viewDir);
|
app.set('views', viewDir);
|
||||||
app.use(loopback.static(path.resolve(rootDir, '../client')));
|
app.use(loopback.static(path.resolve(rootDir, '../client')));
|
||||||
|
app.get('/', function(req, res) {
|
||||||
|
res.render(`${viewDir}/index.ejs`, {
|
||||||
|
assets: require('./assets')
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
|
|
|
@ -2,6 +2,7 @@ FROM node:8.9.4
|
||||||
|
|
||||||
COPY salix /app
|
COPY salix /app
|
||||||
COPY loopback /loopback
|
COPY loopback /loopback
|
||||||
|
COPY nginx/static/webpack-assets.json /loopback/server/
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,8 @@
|
||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
src="/static/routes.js">
|
src="/static/routes.js">
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript"
|
<% for (let jsFile of assets('salix', ['vendor'])) { %>
|
||||||
src="/static/bundle.manifest.js">
|
<script type="text/javascript" src="<%= jsFile %>"></script>
|
||||||
</script>
|
<% } %>
|
||||||
<script type="text/javascript"
|
|
||||||
src="/static/bundle.vendor.js">
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript"
|
|
||||||
src="/static/bundle.salix.js">
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
|
require('require-yaml');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const path = require('path');
|
||||||
|
const merge = require('webpack-merge');
|
||||||
|
const AssetsWebpackPlugin = require('assets-webpack-plugin');
|
||||||
|
const wpConfig = require('./webpack.config.yml');
|
||||||
|
|
||||||
var webpack = require('webpack');
|
let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
|
||||||
var path = require('path');
|
let devMode = env === 'development';
|
||||||
|
let outputPath = path.join(__dirname, wpConfig.buildDir);
|
||||||
|
|
||||||
var devMode = process.env.NODE_ENV !== 'production';
|
let baseConfig = {
|
||||||
|
entry: wpConfig.entry,
|
||||||
var config = {
|
|
||||||
entry: {
|
|
||||||
'bundle.salix': ['salix'],
|
|
||||||
'bundle.auth': ['auth'],
|
|
||||||
'bundle.vendor': ['vendor']
|
|
||||||
},
|
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, './services/nginx/static'),
|
path: outputPath,
|
||||||
filename: '[name].js',
|
publicPath: `${wpConfig.publicPath}/`
|
||||||
publicPath: '/static/',
|
|
||||||
chunkFilename: 'chunk.[name].[chunkhash].js'
|
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
|
@ -52,20 +51,41 @@ var config = {
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
names: ['bundle.vendor', 'bundle.manifest']
|
names: ['vendor', 'manifest']
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
devtool: 'source-map'
|
devtool: 'source-map'
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!devMode) {
|
let prodConfig = {
|
||||||
|
output: {
|
||||||
|
filename: '[name].[chunkhash].js',
|
||||||
|
chunkFilename: 'chunk.[id].[chunkhash].js'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
// FIXME: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/132
|
// FIXME: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/132
|
||||||
// config.plugins.push(
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
// new webpack.optimize.UglifyJsPlugin({
|
minimize: true,
|
||||||
// minimize: true,
|
compress: {warnings: false}
|
||||||
// compress: {warnings: false}
|
}),
|
||||||
// })
|
new AssetsWebpackPlugin({
|
||||||
// );
|
path: outputPath
|
||||||
}
|
}),
|
||||||
|
new webpack.HashedModuleIdsPlugin()
|
||||||
|
],
|
||||||
|
devtool: 'source-map'
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = config;
|
let devConfig = {
|
||||||
|
output: {
|
||||||
|
filename: '[name].js',
|
||||||
|
chunkFilename: 'chunk.[id].js'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.NamedModulesPlugin()
|
||||||
|
],
|
||||||
|
devtool: 'eval'
|
||||||
|
};
|
||||||
|
|
||||||
|
let mrgConfig = devMode ? devConfig : prodConfig;
|
||||||
|
module.exports = merge(baseConfig, mrgConfig);
|
||||||
|
|
Loading…
Reference in New Issue