drop.chapril.org-firefoxsend/webpack.config.js

259 lines
6.7 KiB
JavaScript
Raw Normal View History

2017-08-07 04:32:07 +02:00
const path = require('path');
2017-08-16 06:47:34 +02:00
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
2018-07-12 22:13:49 +02:00
const VersionPlugin = require('./build/version_plugin');
2018-11-02 23:51:27 +01:00
const AndroidIndexPlugin = require('./build/android_index_plugin');
2018-07-13 20:13:09 +02:00
const ExtractTextPlugin = require('extract-text-webpack-plugin');
2017-08-07 04:32:07 +02:00
2018-07-12 22:13:49 +02:00
const webJsOptions = {
2017-12-05 21:45:36 +01:00
babelrc: false,
2018-09-07 07:52:10 +02:00
presets: [
[
'@babel/preset-env',
{
bugfixes: true,
2019-04-11 20:05:40 +02:00
useBuiltIns: 'entry',
corejs: 3
2018-09-07 07:52:10 +02:00
}
]
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
2018-11-23 22:25:22 +01:00
'module:nanohtml',
2018-09-07 07:52:10 +02:00
['@babel/plugin-proposal-class-properties', { loose: false }]
]
2017-12-05 21:45:36 +01:00
};
const serviceWorker = {
target: 'webworker',
entry: {
serviceWorker: './app/serviceWorker.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
2018-07-13 20:36:51 +02:00
},
2018-11-16 18:32:29 +01:00
devtool: 'source-map',
module: {
rules: [
{
test: /\.(png|jpg)$/,
loader: 'file-loader',
options: {
2022-07-26 19:21:12 +02:00
name: '[name].[contenthash:8].[ext]',
esModule: false
2018-11-16 18:32:29 +01:00
}
},
{
test: /\.svg$/,
use: [
{
loader: 'file-loader',
options: {
2022-07-26 19:21:12 +02:00
name: '[name].[contenthash:8].[ext]',
esModule: false
2018-11-16 18:32:29 +01:00
}
},
{
loader: 'svgo-loader',
options: {
plugins: [
2022-07-26 13:56:20 +02:00
{
name: 'removeViewBox',
active: false // true causes stretched images
},
{
name: 'convertStyleToAttrs',
active: true // for CSP, no unsafe-eval
},
{
name: 'removeTitle',
active: true // for smallness
}
2018-11-16 18:32:29 +01:00
]
}
}
]
},
{
// loads all assets from assets/ for use by common/assets.js
2019-09-07 05:00:00 +02:00
test: require.resolve('./common/generate_asset_map.js'),
2018-11-16 18:32:29 +01:00
use: ['babel-loader', 'val-loader']
}
]
},
plugins: [new webpack.IgnorePlugin(/\.\.\/dist/)]
};
2018-07-12 22:13:49 +02:00
const web = {
target: 'web',
entry: {
app: ['./app/main.js']
// android: ['./android/android.js'],
// ios: ['./ios/ios.js']
2018-07-12 22:13:49 +02:00
},
2017-08-07 04:32:07 +02:00
output: {
chunkFilename: '[name].[contenthash:8].js',
filename: '[name].[contenthash:8].js',
path: path.resolve(__dirname, 'dist')
2017-08-07 04:32:07 +02:00
},
module: {
2017-08-14 21:04:03 +02:00
rules: [
2017-08-07 04:32:07 +02:00
{
test: /\.js$/,
2017-08-26 00:38:26 +02:00
oneOf: [
{
loader: 'babel-loader',
2017-08-26 00:38:26 +02:00
include: [
path.resolve(__dirname, 'app'),
path.resolve(__dirname, 'common'),
2018-03-06 01:29:09 +01:00
// some dependencies need to get re-babeled because we
// have different targets than their default configs
path.resolve(
__dirname,
'node_modules/@dannycoates/webcrypto-liner'
),
2019-07-30 00:26:11 +02:00
path.resolve(__dirname, 'node_modules/@fluent'),
2017-11-30 22:41:09 +01:00
path.resolve(__dirname, 'node_modules/intl-pluralrules')
2017-08-26 00:38:26 +02:00
],
2018-07-12 22:13:49 +02:00
options: webJsOptions
2017-08-26 00:38:26 +02:00
},
{
2018-03-06 01:29:09 +01:00
// Strip asserts from our deps, mainly choojs family
2017-08-26 00:38:26 +02:00
include: [path.resolve(__dirname, 'node_modules')],
exclude: [
path.resolve(__dirname, 'node_modules/crc'),
2019-07-30 00:26:11 +02:00
path.resolve(__dirname, 'node_modules/@fluent'),
path.resolve(__dirname, 'node_modules/@sentry'),
path.resolve(__dirname, 'node_modules/tslib'),
path.resolve(__dirname, 'node_modules/webcrypto-core')
],
2017-08-26 00:38:26 +02:00
loader: 'webpack-unassert-loader'
}
]
},
2017-08-16 06:47:34 +02:00
{
test: /\.(png|jpg)$/,
2017-08-16 06:47:34 +02:00
loader: 'file-loader',
options: {
2022-07-26 19:21:12 +02:00
name: '[name].[contenthash:8].[ext]',
esModule: false
2017-08-16 06:47:34 +02:00
}
},
{
test: /\.svg$/,
use: [
{
loader: 'file-loader',
options: {
2022-07-26 19:21:12 +02:00
name: '[name].[contenthash:8].[ext]',
esModule: false
}
},
{
loader: 'svgo-loader',
options: {
2018-02-27 05:28:51 +01:00
plugins: [
2022-07-26 13:56:20 +02:00
{
name: 'cleanupIDs',
active: false
},
{
name: 'removeViewBox',
active: false // true causes stretched images
},
{
name: 'convertStyleToAttrs',
active: true // for CSP, no unsafe-eval
},
{
name: 'removeTitle',
active: true // for smallness
}
2018-02-27 05:28:51 +01:00
]
}
}
]
},
2017-08-16 06:47:34 +02:00
{
2018-03-06 01:29:09 +01:00
// creates style.css with all styles
2017-08-16 06:47:34 +02:00
test: /\.css$/,
2018-07-13 20:13:09 +02:00
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
2022-07-26 18:52:29 +02:00
importLoaders: 1,
esModule: false
2018-07-13 20:13:09 +02:00
}
},
'postcss-loader'
]
})
},
{
test: /\.ftl$/,
use: 'raw-loader'
},
2018-02-21 05:31:27 +01:00
{
2018-03-06 01:29:09 +01:00
// creates test.js for /test
2018-02-21 05:31:27 +01:00
test: require.resolve('./test/frontend/index.js'),
use: ['babel-loader', 'val-loader']
},
{
2018-03-06 01:29:09 +01:00
// loads all assets from assets/ for use by common/assets.js
2019-09-07 05:00:00 +02:00
test: require.resolve('./common/generate_asset_map.js'),
use: ['babel-loader', 'val-loader']
2017-08-07 04:32:07 +02:00
}
]
2017-08-15 20:55:52 +02:00
},
2017-08-16 06:47:34 +02:00
plugins: [
2022-07-26 19:21:12 +02:00
new CopyPlugin({
patterns: [
{
context: 'public',
from: '*.*'
}
]
}),
new webpack.EnvironmentPlugin(['NODE_ENV']),
2018-08-08 00:40:17 +02:00
new webpack.IgnorePlugin(/\.\.\/dist/), // used in common/*.js
2018-07-13 20:13:09 +02:00
new ExtractTextPlugin({
filename: '[name].[md5:contenthash:8].css'
2018-02-20 08:43:15 +01:00
}),
new VersionPlugin(), // used for the /__version__ route
2018-11-02 23:51:27 +01:00
new AndroidIndexPlugin(),
2018-03-06 01:29:09 +01:00
new ManifestPlugin() // used by server side to resolve hashed assets
],
2018-07-13 20:36:51 +02:00
devtool: 'source-map',
devServer: {
2018-10-26 03:55:11 +02:00
before:
process.env.NODE_ENV === 'development' && require('./server/bin/dev'),
compress: true,
2018-07-12 22:13:49 +02:00
hot: false,
host: '0.0.0.0',
2018-06-21 02:05:33 +02:00
proxy: {
'/api/ws': {
target: 'ws://localhost:8081',
ws: true,
secure: false
}
}
}
2017-08-07 04:32:07 +02:00
};
2018-07-12 22:13:49 +02:00
2018-07-13 20:13:09 +02:00
module.exports = (env, argv) => {
const mode = argv.mode || 'production';
2019-07-30 00:26:11 +02:00
// eslint-disable-next-line no-console
2018-07-12 22:13:49 +02:00
console.error(`mode: ${mode}`);
2018-10-26 03:55:11 +02:00
process.env.NODE_ENV = web.mode = serviceWorker.mode = mode;
2018-07-12 22:13:49 +02:00
if (mode === 'development') {
// istanbul instruments the source for code coverage
webJsOptions.plugins.push('istanbul');
web.entry.tests = ['./test/frontend/index.js'];
2018-07-12 22:13:49 +02:00
}
2018-07-13 20:13:09 +02:00
return [web, serviceWorker];
};