Webpack: reorganize module assets rules
This commit is contained in:
parent
0aa0828e13
commit
e5fd60dbdb
4 changed files with 52 additions and 12 deletions
|
@ -12,7 +12,6 @@ const settings = {
|
||||||
test_root_path: `${FE_BUILD_DIR}-test`,
|
test_root_path: `${FE_BUILD_DIR}-test`,
|
||||||
cache_path: 'tmp/cache',
|
cache_path: 'tmp/cache',
|
||||||
resolved_paths: [],
|
resolved_paths: [],
|
||||||
static_assets_extensions: [ '.jpg', '.jpeg', '.png', '.tiff', '.ico', '.svg', '.gif', '.eot', '.otf', '.ttf', '.woff', '.woff2', '.mp3', '.ogg', '.oga' ],
|
|
||||||
extensions: [ '.mjs', '.js', '.sass', '.scss', '.css', '.module.sass', '.module.scss', '.module.css', '.png', '.svg', '.gif', '.jpeg', '.jpg' ],
|
extensions: [ '.mjs', '.js', '.sass', '.scss', '.css', '.module.sass', '.module.scss', '.module.css', '.png', '.svg', '.gif', '.jpeg', '.jpg' ],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
50
webpack/rules/assets.js
Normal file
50
webpack/rules/assets.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
// Asset modules
|
||||||
|
// https://webpack.js.org/guides/asset-modules/
|
||||||
|
|
||||||
|
const { resolve } = require('path');
|
||||||
|
|
||||||
|
// These are processed in reverse-order
|
||||||
|
// We use the name 'packs' instead of 'assets' for legacy reasons
|
||||||
|
module.exports = [{
|
||||||
|
test: /\.(png|svg)/,
|
||||||
|
type: 'asset/resource',
|
||||||
|
include: [
|
||||||
|
resolve('app', 'images'),
|
||||||
|
resolve('node_modules', 'emoji-datasource'),
|
||||||
|
],
|
||||||
|
generator: {
|
||||||
|
filename: 'packs/images/[name]-[contenthash:8][ext]',
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
test: /\.(ttf|eot|svg|woff|woff2)/,
|
||||||
|
type: 'asset/resource',
|
||||||
|
include: [
|
||||||
|
resolve('app', 'fonts'),
|
||||||
|
resolve('node_modules', 'fork-awesome'),
|
||||||
|
resolve('node_modules', '@fontsource'),
|
||||||
|
],
|
||||||
|
generator: {
|
||||||
|
filename: 'packs/fonts/[name]-[contenthash:8][ext]',
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
test: /\.(ogg|oga|mp3)/,
|
||||||
|
type: 'asset/resource',
|
||||||
|
include: resolve('app', 'sounds'),
|
||||||
|
generator: {
|
||||||
|
filename: 'packs/sounds/[name]-[contenthash:8][ext]',
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
test: /\.svg$/,
|
||||||
|
type: 'asset/resource',
|
||||||
|
include: resolve('node_modules', 'twemoji'),
|
||||||
|
generator: {
|
||||||
|
filename: 'packs/emoji/[name]-[contenthash:8][ext]',
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
test: /\.svg$/,
|
||||||
|
type: 'asset/resource',
|
||||||
|
include: resolve('node_modules', 'cryptocurrency-icons'),
|
||||||
|
generator: {
|
||||||
|
filename: 'packs/images/crypto/[name]-[contenthash:8][ext]',
|
||||||
|
},
|
||||||
|
}];
|
|
@ -1,9 +0,0 @@
|
||||||
const { settings } = require('../configuration');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
test: new RegExp(`(${settings.static_assets_extensions.join('|')})$`, 'i'),
|
|
||||||
type: 'asset/resource',
|
|
||||||
generator: {
|
|
||||||
filename: 'packs/media/[contenthash][ext]',
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -3,14 +3,14 @@ const git = require('./babel-git');
|
||||||
const gitRefresh = require('./git-refresh');
|
const gitRefresh = require('./git-refresh');
|
||||||
const buildConfig = require('./babel-build-config');
|
const buildConfig = require('./babel-build-config');
|
||||||
const css = require('./css');
|
const css = require('./css');
|
||||||
const file = require('./file');
|
const assets = require('./assets');
|
||||||
const nodeModules = require('./node_modules');
|
const nodeModules = require('./node_modules');
|
||||||
|
|
||||||
// Webpack loaders are processed in reverse order
|
// Webpack loaders are processed in reverse order
|
||||||
// https://webpack.js.org/concepts/loaders/#loader-features
|
// https://webpack.js.org/concepts/loaders/#loader-features
|
||||||
// Lastly, process static files using file loader
|
// Lastly, process static files using file loader
|
||||||
module.exports = [
|
module.exports = [
|
||||||
file,
|
...assets,
|
||||||
css,
|
css,
|
||||||
nodeModules,
|
nodeModules,
|
||||||
babel,
|
babel,
|
||||||
|
|
Loading…
Reference in a new issue