How do i add Hash to images and other static assets in ionic for cache busting
I have extended default web pack config in Ionic v3 for forcing cache buster.
I am able to fingerprint generated javascript artifacts but unable to fingerprint images and JSON files under the assets folder.
I took Help from Bundled files and cache busting
.
an excerpt of webpack config.js
module.exports = {
// ...
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
},
plugins: [
new WebpackChunkHash({algorithm: 'md5'}) // 'md5' is default value
]
}
Above is the approach for fingerprinting javascript bundles and it's working fine I want to add hashes/Fingerprint images and JSON files inside assets folder i used the same approach for images also but it did not work.
I have extended webpack config.js and added a new rule for images.
By default webpack directly copies the images and assets to the output folder.
Copy Config.js
module.exports = {
copyAssets: {
src: ['{{SRC}}/assets/**/*'],
dest: '{{WWW}}/assets'
},
copyIndexContent: {
src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
dest: '{{WWW}}'
},
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
here images and other assets are directly copied.
I have added a new rule in extended webpack.config.js but the build process is ignoring it. how to fix this issue??
excerpt of webpack config.js
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
entire Webpack.config.js
/*
* The webpack config exports an object that has a valid webpack configuration
* For each environment name. By default, there are two Ionic environments:
* "dev" and "prod". As such, the webpack.config.js exports a dictionary object
* with "keys" for "dev" and "prod", where the value is a valid webpack configuration
* For details on configuring webpack, see their documentation here
* https://webpack.js.org/configuration/
*/
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
var optimizedProdLoaders = [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.js$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
]
},
{
test: /.ts$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
},
{
loader: process.env.IONIC_WEBPACK_LOADER
}
]
}
];
function getProdLoaders() {
if (process.env.IONIC_OPTIMIZE_JS === 'true') {
return optimizedProdLoaders;
}
return devConfig.module.loaders;
}
var devConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.ts$/,
loader: process.env.IONIC_WEBPACK_LOADER
},
{
test: /.(jpg|png)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
}},
]
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
var prodConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: getProdLoaders()
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin(),
new ModuleConcatPlugin(),
new PurifyPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
module.exports = {
dev: devConfig,
prod: prodConfig
}
javascript angular webpack ionic3
add a comment |
I have extended default web pack config in Ionic v3 for forcing cache buster.
I am able to fingerprint generated javascript artifacts but unable to fingerprint images and JSON files under the assets folder.
I took Help from Bundled files and cache busting
.
an excerpt of webpack config.js
module.exports = {
// ...
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
},
plugins: [
new WebpackChunkHash({algorithm: 'md5'}) // 'md5' is default value
]
}
Above is the approach for fingerprinting javascript bundles and it's working fine I want to add hashes/Fingerprint images and JSON files inside assets folder i used the same approach for images also but it did not work.
I have extended webpack config.js and added a new rule for images.
By default webpack directly copies the images and assets to the output folder.
Copy Config.js
module.exports = {
copyAssets: {
src: ['{{SRC}}/assets/**/*'],
dest: '{{WWW}}/assets'
},
copyIndexContent: {
src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
dest: '{{WWW}}'
},
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
here images and other assets are directly copied.
I have added a new rule in extended webpack.config.js but the build process is ignoring it. how to fix this issue??
excerpt of webpack config.js
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
entire Webpack.config.js
/*
* The webpack config exports an object that has a valid webpack configuration
* For each environment name. By default, there are two Ionic environments:
* "dev" and "prod". As such, the webpack.config.js exports a dictionary object
* with "keys" for "dev" and "prod", where the value is a valid webpack configuration
* For details on configuring webpack, see their documentation here
* https://webpack.js.org/configuration/
*/
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
var optimizedProdLoaders = [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.js$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
]
},
{
test: /.ts$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
},
{
loader: process.env.IONIC_WEBPACK_LOADER
}
]
}
];
function getProdLoaders() {
if (process.env.IONIC_OPTIMIZE_JS === 'true') {
return optimizedProdLoaders;
}
return devConfig.module.loaders;
}
var devConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.ts$/,
loader: process.env.IONIC_WEBPACK_LOADER
},
{
test: /.(jpg|png)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
}},
]
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
var prodConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: getProdLoaders()
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin(),
new ModuleConcatPlugin(),
new PurifyPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
module.exports = {
dev: devConfig,
prod: prodConfig
}
javascript angular webpack ionic3
Did you run the build in prod mode?
– emix
Dec 27 '18 at 9:44
@emix yes I did AFAIK Angular provides us withoutput-hashing
but ionic does not that's why I have moved to webpack config for hashing
– Vikas
Dec 27 '18 at 9:46
what about this [hash] -> loader:'url-loader?limit=1024&name=images/[name][hash].[ext]'
– Vadim Hulevich
Dec 30 '18 at 9:02
Have you seen this other SO question? stackoverflow.com/questions/43064019/…
– Derek Nguyen
Jan 2 at 4:40
@DerekNguyen yes i did but no help
– Vikas
Jan 2 at 5:12
add a comment |
I have extended default web pack config in Ionic v3 for forcing cache buster.
I am able to fingerprint generated javascript artifacts but unable to fingerprint images and JSON files under the assets folder.
I took Help from Bundled files and cache busting
.
an excerpt of webpack config.js
module.exports = {
// ...
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
},
plugins: [
new WebpackChunkHash({algorithm: 'md5'}) // 'md5' is default value
]
}
Above is the approach for fingerprinting javascript bundles and it's working fine I want to add hashes/Fingerprint images and JSON files inside assets folder i used the same approach for images also but it did not work.
I have extended webpack config.js and added a new rule for images.
By default webpack directly copies the images and assets to the output folder.
Copy Config.js
module.exports = {
copyAssets: {
src: ['{{SRC}}/assets/**/*'],
dest: '{{WWW}}/assets'
},
copyIndexContent: {
src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
dest: '{{WWW}}'
},
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
here images and other assets are directly copied.
I have added a new rule in extended webpack.config.js but the build process is ignoring it. how to fix this issue??
excerpt of webpack config.js
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
entire Webpack.config.js
/*
* The webpack config exports an object that has a valid webpack configuration
* For each environment name. By default, there are two Ionic environments:
* "dev" and "prod". As such, the webpack.config.js exports a dictionary object
* with "keys" for "dev" and "prod", where the value is a valid webpack configuration
* For details on configuring webpack, see their documentation here
* https://webpack.js.org/configuration/
*/
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
var optimizedProdLoaders = [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.js$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
]
},
{
test: /.ts$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
},
{
loader: process.env.IONIC_WEBPACK_LOADER
}
]
}
];
function getProdLoaders() {
if (process.env.IONIC_OPTIMIZE_JS === 'true') {
return optimizedProdLoaders;
}
return devConfig.module.loaders;
}
var devConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.ts$/,
loader: process.env.IONIC_WEBPACK_LOADER
},
{
test: /.(jpg|png)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
}},
]
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
var prodConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: getProdLoaders()
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin(),
new ModuleConcatPlugin(),
new PurifyPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
module.exports = {
dev: devConfig,
prod: prodConfig
}
javascript angular webpack ionic3
I have extended default web pack config in Ionic v3 for forcing cache buster.
I am able to fingerprint generated javascript artifacts but unable to fingerprint images and JSON files under the assets folder.
I took Help from Bundled files and cache busting
.
an excerpt of webpack config.js
module.exports = {
// ...
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
},
plugins: [
new WebpackChunkHash({algorithm: 'md5'}) // 'md5' is default value
]
}
Above is the approach for fingerprinting javascript bundles and it's working fine I want to add hashes/Fingerprint images and JSON files inside assets folder i used the same approach for images also but it did not work.
I have extended webpack config.js and added a new rule for images.
By default webpack directly copies the images and assets to the output folder.
Copy Config.js
module.exports = {
copyAssets: {
src: ['{{SRC}}/assets/**/*'],
dest: '{{WWW}}/assets'
},
copyIndexContent: {
src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
dest: '{{WWW}}'
},
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
here images and other assets are directly copied.
I have added a new rule in extended webpack.config.js but the build process is ignoring it. how to fix this issue??
excerpt of webpack config.js
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
entire Webpack.config.js
/*
* The webpack config exports an object that has a valid webpack configuration
* For each environment name. By default, there are two Ionic environments:
* "dev" and "prod". As such, the webpack.config.js exports a dictionary object
* with "keys" for "dev" and "prod", where the value is a valid webpack configuration
* For details on configuring webpack, see their documentation here
* https://webpack.js.org/configuration/
*/
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
var optimizedProdLoaders = [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.js$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
]
},
{
test: /.ts$/,
loader: [
{
loader: process.env.IONIC_CACHE_LOADER
},
{
loader: '@angular-devkit/build-optimizer/webpack-loader',
options: {
sourceMap: true
}
},
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
},
{
loader: process.env.IONIC_WEBPACK_LOADER
}
]
}
];
function getProdLoaders() {
if (process.env.IONIC_OPTIMIZE_JS === 'true') {
return optimizedProdLoaders;
}
return devConfig.module.loaders;
}
var devConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.ts$/,
loader: process.env.IONIC_WEBPACK_LOADER
},
{
test: /.(jpg|png)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
}},
]
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
var prodConfig = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: '[name].js',
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: getProdLoaders()
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
ionicWebpackFactory.getCommonChunksPlugin(),
new ModuleConcatPlugin(),
new PurifyPlugin()
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
module.exports = {
dev: devConfig,
prod: prodConfig
}
javascript angular webpack ionic3
javascript angular webpack ionic3
edited Jan 4 at 9:10
Vikas
asked Dec 27 '18 at 9:42
VikasVikas
5,60141436
5,60141436
Did you run the build in prod mode?
– emix
Dec 27 '18 at 9:44
@emix yes I did AFAIK Angular provides us withoutput-hashing
but ionic does not that's why I have moved to webpack config for hashing
– Vikas
Dec 27 '18 at 9:46
what about this [hash] -> loader:'url-loader?limit=1024&name=images/[name][hash].[ext]'
– Vadim Hulevich
Dec 30 '18 at 9:02
Have you seen this other SO question? stackoverflow.com/questions/43064019/…
– Derek Nguyen
Jan 2 at 4:40
@DerekNguyen yes i did but no help
– Vikas
Jan 2 at 5:12
add a comment |
Did you run the build in prod mode?
– emix
Dec 27 '18 at 9:44
@emix yes I did AFAIK Angular provides us withoutput-hashing
but ionic does not that's why I have moved to webpack config for hashing
– Vikas
Dec 27 '18 at 9:46
what about this [hash] -> loader:'url-loader?limit=1024&name=images/[name][hash].[ext]'
– Vadim Hulevich
Dec 30 '18 at 9:02
Have you seen this other SO question? stackoverflow.com/questions/43064019/…
– Derek Nguyen
Jan 2 at 4:40
@DerekNguyen yes i did but no help
– Vikas
Jan 2 at 5:12
Did you run the build in prod mode?
– emix
Dec 27 '18 at 9:44
Did you run the build in prod mode?
– emix
Dec 27 '18 at 9:44
@emix yes I did AFAIK Angular provides us with
output-hashing
but ionic does not that's why I have moved to webpack config for hashing– Vikas
Dec 27 '18 at 9:46
@emix yes I did AFAIK Angular provides us with
output-hashing
but ionic does not that's why I have moved to webpack config for hashing– Vikas
Dec 27 '18 at 9:46
what about this [hash] -> loader:'url-loader?limit=1024&name=images/[name][hash].[ext]'
– Vadim Hulevich
Dec 30 '18 at 9:02
what about this [hash] -> loader:'url-loader?limit=1024&name=images/[name][hash].[ext]'
– Vadim Hulevich
Dec 30 '18 at 9:02
Have you seen this other SO question? stackoverflow.com/questions/43064019/…
– Derek Nguyen
Jan 2 at 4:40
Have you seen this other SO question? stackoverflow.com/questions/43064019/…
– Derek Nguyen
Jan 2 at 4:40
@DerekNguyen yes i did but no help
– Vikas
Jan 2 at 5:12
@DerekNguyen yes i did but no help
– Vikas
Jan 2 at 5:12
add a comment |
2 Answers
2
active
oldest
votes
Using webpack4 you should not need any additional plugins or loaders.
It will give you the naming option [contenthash].
Also, it looks like you have this block nested under the test: .ts block.
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
Ultimately, you can do something like this:
// Copy static assets over with file-loader
{
test: /.(ico)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: '[name].[contenthash].[ext]'},
},
{
test: /.(woff|woff2|eot|ttf|otf)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'fonts/[name].[contenthash].[ext]'},
},
{
test: /.(jpg|gif|png|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'images/[name].[contenthash].[ext]'},
}
]
Using [chunkhash] instead of content should still work, and if you're not using webpack4 do that, but otherwise for more information see this issue for explanation.
For more help, read the longterm caching performance guide from google and the latest caching documentation from webpack.
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
add a comment |
Using webpack-assets-manifest
you can generate a map of asset names to fingerprinted names like so:
{
"images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg"
}
Using this manifest you can then rename the assets in destination folder, and use the "correct", hash-inclusive src or href in your project.
The fix isn't framework-specific.
Lemme give it a try
– Vikas
Jan 10 at 3:50
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942876%2fhow-do-i-add-hash-to-images-and-other-static-assets-in-ionic-for-cache-busting%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using webpack4 you should not need any additional plugins or loaders.
It will give you the naming option [contenthash].
Also, it looks like you have this block nested under the test: .ts block.
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
Ultimately, you can do something like this:
// Copy static assets over with file-loader
{
test: /.(ico)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: '[name].[contenthash].[ext]'},
},
{
test: /.(woff|woff2|eot|ttf|otf)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'fonts/[name].[contenthash].[ext]'},
},
{
test: /.(jpg|gif|png|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'images/[name].[contenthash].[ext]'},
}
]
Using [chunkhash] instead of content should still work, and if you're not using webpack4 do that, but otherwise for more information see this issue for explanation.
For more help, read the longterm caching performance guide from google and the latest caching documentation from webpack.
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
add a comment |
Using webpack4 you should not need any additional plugins or loaders.
It will give you the naming option [contenthash].
Also, it looks like you have this block nested under the test: .ts block.
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
Ultimately, you can do something like this:
// Copy static assets over with file-loader
{
test: /.(ico)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: '[name].[contenthash].[ext]'},
},
{
test: /.(woff|woff2|eot|ttf|otf)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'fonts/[name].[contenthash].[ext]'},
},
{
test: /.(jpg|gif|png|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'images/[name].[contenthash].[ext]'},
}
]
Using [chunkhash] instead of content should still work, and if you're not using webpack4 do that, but otherwise for more information see this issue for explanation.
For more help, read the longterm caching performance guide from google and the latest caching documentation from webpack.
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
add a comment |
Using webpack4 you should not need any additional plugins or loaders.
It will give you the naming option [contenthash].
Also, it looks like you have this block nested under the test: .ts block.
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
Ultimately, you can do something like this:
// Copy static assets over with file-loader
{
test: /.(ico)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: '[name].[contenthash].[ext]'},
},
{
test: /.(woff|woff2|eot|ttf|otf)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'fonts/[name].[contenthash].[ext]'},
},
{
test: /.(jpg|gif|png|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'images/[name].[contenthash].[ext]'},
}
]
Using [chunkhash] instead of content should still work, and if you're not using webpack4 do that, but otherwise for more information see this issue for explanation.
For more help, read the longterm caching performance guide from google and the latest caching documentation from webpack.
Using webpack4 you should not need any additional plugins or loaders.
It will give you the naming option [contenthash].
Also, it looks like you have this block nested under the test: .ts block.
{
test: /.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name:'[name].[hash].[ext]',//adding hash for cache busting
outputPath:'assets/imgs',
publicPath:'assets/imgs'
},
Ultimately, you can do something like this:
// Copy static assets over with file-loader
{
test: /.(ico)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: '[name].[contenthash].[ext]'},
},
{
test: /.(woff|woff2|eot|ttf|otf)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'fonts/[name].[contenthash].[ext]'},
},
{
test: /.(jpg|gif|png|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader', options: {name: 'images/[name].[contenthash].[ext]'},
}
]
Using [chunkhash] instead of content should still work, and if you're not using webpack4 do that, but otherwise for more information see this issue for explanation.
For more help, read the longterm caching performance guide from google and the latest caching documentation from webpack.
edited Jan 11 at 5:51
answered Jan 11 at 5:42
adamrightsadamrights
660412
660412
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
add a comment |
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
If I go for webpack 4 I have to revamp the entire project which is not possible at this stage I need to find a workaround by extending ionic webpack configuration.1 paulsouche/angular6-ionic4-webpack4-starter This repo has the same configuration which you have mentioned Though this would work client wants this with minimalistic changes Unfortunately i can't use this solution Thanks a lot :)
– Vikas
Jan 12 at 6:35
add a comment |
Using webpack-assets-manifest
you can generate a map of asset names to fingerprinted names like so:
{
"images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg"
}
Using this manifest you can then rename the assets in destination folder, and use the "correct", hash-inclusive src or href in your project.
The fix isn't framework-specific.
Lemme give it a try
– Vikas
Jan 10 at 3:50
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
add a comment |
Using webpack-assets-manifest
you can generate a map of asset names to fingerprinted names like so:
{
"images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg"
}
Using this manifest you can then rename the assets in destination folder, and use the "correct", hash-inclusive src or href in your project.
The fix isn't framework-specific.
Lemme give it a try
– Vikas
Jan 10 at 3:50
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
add a comment |
Using webpack-assets-manifest
you can generate a map of asset names to fingerprinted names like so:
{
"images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg"
}
Using this manifest you can then rename the assets in destination folder, and use the "correct", hash-inclusive src or href in your project.
The fix isn't framework-specific.
Using webpack-assets-manifest
you can generate a map of asset names to fingerprinted names like so:
{
"images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg"
}
Using this manifest you can then rename the assets in destination folder, and use the "correct", hash-inclusive src or href in your project.
The fix isn't framework-specific.
answered Jan 10 at 0:55
o.v.o.v.
19.6k44975
19.6k44975
Lemme give it a try
– Vikas
Jan 10 at 3:50
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
add a comment |
Lemme give it a try
– Vikas
Jan 10 at 3:50
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
Lemme give it a try
– Vikas
Jan 10 at 3:50
Lemme give it a try
– Vikas
Jan 10 at 3:50
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
This does not solve my problem path in HTML template and CSS are not updated I have to use a custom script for it which I don't want to, I want web pack to fingerprint assets and update paths in relevant files accordingly ,Thanx for your help but the same can be achieved by hashly :)
– Vikas
Jan 11 at 5:15
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
You have to use loaders (survivejs.com/webpack/loading/images) to leverage webpack hashing, or you need to use external hashing. Using a manifest and updating links before bundling is the way to go. If you don't use loaders for some assets, you can't use webpack hashing for those assets! If you don't want to take the manifest and update the asset hashes programmatically before bundling, pay a freelancer
– o.v.
Jan 16 at 22:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942876%2fhow-do-i-add-hash-to-images-and-other-static-assets-in-ionic-for-cache-busting%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you run the build in prod mode?
– emix
Dec 27 '18 at 9:44
@emix yes I did AFAIK Angular provides us with
output-hashing
but ionic does not that's why I have moved to webpack config for hashing– Vikas
Dec 27 '18 at 9:46
what about this [hash] -> loader:'url-loader?limit=1024&name=images/[name][hash].[ext]'
– Vadim Hulevich
Dec 30 '18 at 9:02
Have you seen this other SO question? stackoverflow.com/questions/43064019/…
– Derek Nguyen
Jan 2 at 4:40
@DerekNguyen yes i did but no help
– Vikas
Jan 2 at 5:12