sforkowany z mirror/soapbox
Webpack: switch build directory to 'static' instead of 'static/packs', fix sw.js
rodzic
969653eaa4
commit
f061954fdb
|
@ -9,8 +9,14 @@
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
/static/packs
|
/static/packs
|
||||||
|
/static/packs-test
|
||||||
/static/emoji
|
/static/emoji
|
||||||
/static/index.html
|
/static/index.html
|
||||||
|
/static/index.html.gz
|
||||||
|
/static/manifest.json
|
||||||
|
/static/manifest.json.gz
|
||||||
|
/static/report.html
|
||||||
|
/static/sw.js
|
||||||
/static/instance/**
|
/static/instance/**
|
||||||
!/static/instance/**.example
|
!/static/instance/**.example
|
||||||
!/static/instance/**.example.*
|
!/static/instance/**.example.*
|
||||||
|
|
|
@ -11,10 +11,6 @@ const settings = {
|
||||||
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 removeOuterSlashes(string) {
|
|
||||||
return string.replace(/^\/*/, '').replace(/\/*$/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPublicOutputPath() {
|
function getPublicOutputPath() {
|
||||||
if (env.NODE_ENV === 'test') {
|
if (env.NODE_ENV === 'test') {
|
||||||
return 'packs-test';
|
return 'packs-test';
|
||||||
|
@ -23,25 +19,14 @@ function getPublicOutputPath() {
|
||||||
return 'packs';
|
return 'packs';
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatPublicPath(host = '', path = '') {
|
function packsPath(path) {
|
||||||
let formattedHost = removeOuterSlashes(host);
|
return join(settings.public_output_path, path);
|
||||||
if (formattedHost && !/^http/i.test(formattedHost)) {
|
|
||||||
formattedHost = `//${formattedHost}`;
|
|
||||||
}
|
|
||||||
const formattedPath = removeOuterSlashes(path);
|
|
||||||
return `${formattedHost}/${formattedPath}/`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = {
|
|
||||||
path: join(__dirname, '..', 'static', settings.public_output_path),
|
|
||||||
publicPath: formatPublicPath(env.CDN_HOST, settings.public_output_path),
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
settings,
|
settings,
|
||||||
env: {
|
env: {
|
||||||
CDN_HOST: env.CDN_HOST,
|
|
||||||
NODE_ENV: env.NODE_ENV,
|
NODE_ENV: env.NODE_ENV,
|
||||||
},
|
},
|
||||||
output,
|
packsPath,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||||
console.log('Running in development mode'); // eslint-disable-line no-console
|
console.log('Running in development mode'); // eslint-disable-line no-console
|
||||||
|
|
||||||
const { resolve } = require('path');
|
|
||||||
const { merge } = require('webpack-merge');
|
const { merge } = require('webpack-merge');
|
||||||
const sharedConfig = require('./shared');
|
const sharedConfig = require('./shared');
|
||||||
const { settings, output } = require('./configuration');
|
|
||||||
|
|
||||||
const watchOptions = {};
|
const watchOptions = {};
|
||||||
|
|
||||||
|
@ -72,11 +70,9 @@ module.exports = merge(sharedConfig, {
|
||||||
port: 3036,
|
port: 3036,
|
||||||
https: false,
|
https: false,
|
||||||
hot: false,
|
hot: false,
|
||||||
contentBase: resolve(__dirname, '..', settings.public_root_path),
|
|
||||||
inline: true,
|
inline: true,
|
||||||
useLocalIp: false,
|
useLocalIp: false,
|
||||||
public: 'localhost:3036',
|
public: 'localhost:3036',
|
||||||
publicPath: output.publicPath,
|
|
||||||
historyApiFallback: {
|
historyApiFallback: {
|
||||||
disableDotRule: true,
|
disableDotRule: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||||
const OfflinePlugin = require('offline-plugin');
|
const OfflinePlugin = require('offline-plugin');
|
||||||
const TerserPlugin = require('terser-webpack-plugin');
|
const TerserPlugin = require('terser-webpack-plugin');
|
||||||
const CompressionPlugin = require('compression-webpack-plugin');
|
const CompressionPlugin = require('compression-webpack-plugin');
|
||||||
const { output } = require('./configuration');
|
|
||||||
const sharedConfig = require('./shared');
|
const sharedConfig = require('./shared');
|
||||||
|
|
||||||
module.exports = merge(sharedConfig, {
|
module.exports = merge(sharedConfig, {
|
||||||
|
@ -44,7 +44,6 @@ module.exports = merge(sharedConfig, {
|
||||||
logLevel: 'silent', // do not bother Webpacker, who runs with --json and parses stdout
|
logLevel: 'silent', // do not bother Webpacker, who runs with --json and parses stdout
|
||||||
}),
|
}),
|
||||||
new OfflinePlugin({
|
new OfflinePlugin({
|
||||||
publicPath: output.publicPath, // sw.js must be served from the root to avoid scope issues
|
|
||||||
caches: {
|
caches: {
|
||||||
main: [':rest:'],
|
main: [':rest:'],
|
||||||
additional: [':externals:'],
|
additional: [':externals:'],
|
||||||
|
@ -64,6 +63,15 @@ module.exports = merge(sharedConfig, {
|
||||||
externals: [
|
externals: [
|
||||||
'/emoji/1f602.svg', // used for emoji picker dropdown
|
'/emoji/1f602.svg', // used for emoji picker dropdown
|
||||||
'/emoji/sheet_13.png', // used in emoji-mart
|
'/emoji/sheet_13.png', // used in emoji-mart
|
||||||
|
|
||||||
|
// Default emoji reacts
|
||||||
|
'/emoji/1f44d.svg', // Thumbs up
|
||||||
|
'/emoji/2764.svg', // Heart
|
||||||
|
'/emoji/1f606.svg', // Laughing
|
||||||
|
'/emoji/1f62e.svg', // Surprised
|
||||||
|
'/emoji/1f622.svg', // Crying
|
||||||
|
'/emoji/1f629.svg', // Weary
|
||||||
|
'/emoji/1f621.svg', // Angry (Spinster)
|
||||||
],
|
],
|
||||||
excludes: [
|
excludes: [
|
||||||
'**/*.gz',
|
'**/*.gz',
|
||||||
|
@ -77,10 +85,8 @@ module.exports = merge(sharedConfig, {
|
||||||
'**/*.woff',
|
'**/*.woff',
|
||||||
],
|
],
|
||||||
// ServiceWorker: {
|
// ServiceWorker: {
|
||||||
// entry: `imports-loader?ATTACHMENT_HOST=>${encodeURIComponent(JSON.stringify(attachmentHost))}!${encodeURI(path.join(__dirname, '../app/soapbox/service_worker/entry.js'))}`,
|
// entry: join(__dirname, '../app/soapbox/service_worker/entry.js'),
|
||||||
// cacheName: 'soapbox',
|
// cacheName: 'soapbox',
|
||||||
// output: '../assets/sw.js',
|
|
||||||
// publicPath: '/sw.js',
|
|
||||||
// minify: true,
|
// minify: true,
|
||||||
// },
|
// },
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
const { settings } = require('../configuration');
|
const { settings, packsPath } = 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 'media/[path][name]-[hash].[ext]';
|
return packsPath('media/[path][name]-[hash].[ext]');
|
||||||
}
|
}
|
||||||
return 'media/[folder]/[name]-[hash:8].[ext]';
|
return packsPath('media/[folder]/[name]-[hash:8].[ext]');
|
||||||
},
|
},
|
||||||
context: join(settings.source_path),
|
context: join(settings.source_path),
|
||||||
},
|
},
|
||||||
|
|
|
@ -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, output } = require('./configuration');
|
const { env, settings, packsPath } = require('./configuration');
|
||||||
const rules = require('./rules');
|
const rules = require('./rules');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -18,11 +18,11 @@ module.exports = {
|
||||||
),
|
),
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
filename: 'js/[name]-[chunkhash].js',
|
filename: packsPath('js/[name]-[chunkhash].js'),
|
||||||
chunkFilename: 'js/[name]-[chunkhash].chunk.js',
|
chunkFilename: packsPath('js/[name]-[chunkhash].chunk.js'),
|
||||||
hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
|
hotUpdateChunkFilename: packsPath('js/[id]-[hash].hot-update.js'),
|
||||||
path: output.path,
|
path: join(__dirname, '..', 'static'),
|
||||||
publicPath: output.publicPath,
|
publicPath: '/',
|
||||||
},
|
},
|
||||||
|
|
||||||
optimization: {
|
optimization: {
|
||||||
|
@ -59,8 +59,8 @@ module.exports = {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: 'css/[name]-[contenthash:8].css',
|
filename: packsPath('css/[name]-[contenthash:8].css'),
|
||||||
chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
|
chunkFilename: packsPath('css/[name]-[contenthash:8].chunk.css'),
|
||||||
}),
|
}),
|
||||||
new AssetsManifestPlugin({
|
new AssetsManifestPlugin({
|
||||||
integrity: false,
|
integrity: false,
|
||||||
|
@ -90,9 +90,7 @@ module.exports = {
|
||||||
useShortDoctype: true,
|
useShortDoctype: true,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackHarddiskPlugin({
|
new HtmlWebpackHarddiskPlugin(),
|
||||||
outputPath: join(__dirname, '..', 'static'),
|
|
||||||
}),
|
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [{
|
patterns: [{
|
||||||
from: join(__dirname, '../node_modules/twemoji/assets/svg'),
|
from: join(__dirname, '../node_modules/twemoji/assets/svg'),
|
||||||
|
|
Ładowanie…
Reference in New Issue