Webpack: output to 'static-test' for tests

This commit is contained in:
Alex Gleason 2021-07-21 16:43:41 -05:00
parent f061954fdb
commit 655d5393a3
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 19 additions and 24 deletions

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ yarn-error.log*
!/static/instance/**.example !/static/instance/**.example
!/static/instance/**.example.* !/static/instance/**.example.*
!/static/instance/**.example/** !/static/instance/**.example/**
/static-test

View file

@ -4,29 +4,23 @@ const { env } = require('process');
const settings = { const settings = {
source_path: 'app', source_path: 'app',
public_root_path: 'static', public_root_path: 'static',
public_output_path: getPublicOutputPath(), test_root_path: 'static-test',
cache_path: 'tmp/cache/webpacker', cache_path: 'tmp/cache/webpacker',
resolved_paths: [], resolved_paths: [],
static_assets_extensions: [ '.jpg', '.jpeg', '.png', '.tiff', '.ico', '.svg', '.gif', '.eot', '.otf', '.ttf', '.woff', '.woff2' ], static_assets_extensions: [ '.jpg', '.jpeg', '.png', '.tiff', '.ico', '.svg', '.gif', '.eot', '.otf', '.ttf', '.woff', '.woff2' ],
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' ],
}; };
function getPublicOutputPath() { const outputDir = env.NODE_ENV === 'test' ? settings.test_root_path : settings.public_root_path;
if (env.NODE_ENV === 'test') {
return 'packs-test';
}
return 'packs'; const output = {
} path: join(__dirname, '..', outputDir),
};
function packsPath(path) {
return join(settings.public_output_path, path);
}
module.exports = { module.exports = {
settings, settings,
env: { env: {
NODE_ENV: env.NODE_ENV, NODE_ENV: env.NODE_ENV,
}, },
packsPath, output,
}; };

View file

@ -1,5 +1,5 @@
const { join } = require('path'); const { join } = require('path');
const { settings, packsPath } = require('../configuration'); const { settings } = require('../configuration');
module.exports = { module.exports = {
test: new RegExp(`(${settings.static_assets_extensions.join('|')})$`, 'i'), test: new RegExp(`(${settings.static_assets_extensions.join('|')})$`, 'i'),
@ -9,9 +9,9 @@ module.exports = {
options: { options: {
name(file) { name(file) {
if (file.includes(settings.source_path)) { if (file.includes(settings.source_path)) {
return packsPath('media/[path][name]-[hash].[ext]'); return 'packs/media/[path][name]-[hash].[ext]';
} }
return packsPath('media/[folder]/[name]-[hash:8].[ext]'); return 'packs/media/[folder]/[name]-[hash:8].[ext]';
}, },
context: join(settings.source_path), context: join(settings.source_path),
}, },

View file

@ -8,7 +8,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin'); const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
const CopyPlugin = require('copy-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin');
const { UnusedFilesWebpackPlugin } = require('unused-files-webpack-plugin'); const { UnusedFilesWebpackPlugin } = require('unused-files-webpack-plugin');
const { env, settings, packsPath } = require('./configuration'); const { env, settings, output } = require('./configuration');
const rules = require('./rules'); const rules = require('./rules');
module.exports = { module.exports = {
@ -18,10 +18,10 @@ module.exports = {
), ),
output: { output: {
filename: packsPath('js/[name]-[chunkhash].js'), filename: 'packs/js/[name]-[chunkhash].js',
chunkFilename: packsPath('js/[name]-[chunkhash].chunk.js'), chunkFilename: 'packs/js/[name]-[chunkhash].chunk.js',
hotUpdateChunkFilename: packsPath('js/[id]-[hash].hot-update.js'), hotUpdateChunkFilename: 'packs/js/[id]-[hash].hot-update.js',
path: join(__dirname, '..', 'static'), path: output.path,
publicPath: '/', publicPath: '/',
}, },
@ -59,8 +59,8 @@ module.exports = {
}, },
), ),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: packsPath('css/[name]-[contenthash:8].css'), filename: 'packs/css/[name]-[contenthash:8].css',
chunkFilename: packsPath('css/[name]-[contenthash:8].chunk.css'), chunkFilename: 'packs/css/[name]-[contenthash:8].chunk.css',
}), }),
new AssetsManifestPlugin({ new AssetsManifestPlugin({
integrity: false, integrity: false,
@ -94,10 +94,10 @@ module.exports = {
new CopyPlugin({ new CopyPlugin({
patterns: [{ patterns: [{
from: join(__dirname, '../node_modules/twemoji/assets/svg'), from: join(__dirname, '../node_modules/twemoji/assets/svg'),
to: join(__dirname, '../static/emoji'), to: join(output.path, 'emoji'),
}, { }, {
from: join(__dirname, '../node_modules/emoji-datasource/img/twitter/sheets/32.png'), from: join(__dirname, '../node_modules/emoji-datasource/img/twitter/sheets/32.png'),
to: join(__dirname, '../static/emoji/sheet_13.png'), to: join(output.path, 'emoji/sheet_13.png'),
}], }],
options: { options: {
concurrency: 100, concurrency: 100,