1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-14 07:02:30 +01:00
send/webpack.config.js

215 lines
6.0 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');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
2017-08-28 00:19:58 +02:00
const IS_DEV = process.env.NODE_ENV === 'development';
2017-08-07 04:32:07 +02:00
2017-12-05 21:45:36 +01:00
const regularJSOptions = {
babelrc: false,
presets: [['env', { modules: false }], 'stage-2'],
2018-03-06 01:29:09 +01:00
// yo-yoify converts html template strings to direct dom api calls
2017-12-05 21:45:36 +01:00
plugins: ['yo-yoify']
};
2018-02-21 05:31:27 +01:00
const entry = {
2018-03-06 01:29:09 +01:00
// babel-polyfill and fluent are directly included in vendor
// because they are not explicitly referenced by app
2018-02-21 05:31:27 +01:00
vendor: ['babel-polyfill', 'fluent'],
app: ['./app/main.js'],
style: ['./app/main.css']
};
if (IS_DEV) {
entry.tests = ['./test/frontend/index.js'];
2018-03-06 01:29:09 +01:00
// istanbul instruments the source for code coverage
2018-02-21 05:31:27 +01:00
regularJSOptions.plugins.push('istanbul');
}
2017-08-07 04:32:07 +02:00
module.exports = {
2018-02-21 05:31:27 +01:00
entry,
2017-08-07 04:32:07 +02:00
output: {
filename: '[name].[chunkhash:8].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
2017-08-07 04:32:07 +02:00
},
2017-08-28 00:19:58 +02:00
devtool: IS_DEV && 'inline-source-map',
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: [
{
include: require.resolve('./assets/cryptofill'),
use: [
{
loader: 'file-loader',
options: {
name: '[name].[hash:8].[ext]'
}
}
]
},
2017-12-05 21:45:36 +01:00
{
2018-03-06 01:29:09 +01:00
// inlines version from package.json into header/index.js
2017-12-05 21:45:36 +01:00
include: require.resolve('./app/templates/header'),
use: [
{
loader: 'babel-loader',
options: regularJSOptions
},
'./build/version_loader'
]
},
{
2018-03-06 01:29:09 +01:00
// fluent gets exposed as a global so that each language script
// can load independently and share it.
2017-08-26 00:38:26 +02:00
include: [path.dirname(require.resolve('fluent'))],
use: [
{
loader: 'expose-loader',
options: 'fluent'
},
{
loader: 'babel-loader',
options: {
2018-02-20 19:56:06 +01:00
presets: [['env', { modules: false }], 'stage-3']
2017-08-26 00:38:26 +02:00
}
}
]
},
{
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
2017-11-30 22:41:09 +01:00
path.resolve(__dirname, 'node_modules/testpilot-ga/src'),
path.resolve(__dirname, 'node_modules/fluent-intl-polyfill'),
path.resolve(__dirname, 'node_modules/intl-pluralrules')
2017-08-26 00:38:26 +02:00
],
2017-12-05 21:45:36 +01:00
options: regularJSOptions
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')],
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: {
name: '[name].[hash:8].[ext]'
2017-08-16 06:47:34 +02:00
}
},
{
test: /\.svg$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[hash:8].[ext]'
}
},
{
loader: 'svgo-loader',
options: {
2018-02-27 05:28:51 +01:00
plugins: [
2018-03-06 01:29:09 +01:00
{ removeViewBox: false }, // true causes stretched images
{ convertStyleToAttrs: true }, // for CSP, no unsafe-eval
{ removeTitle: 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$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: { modules: false, importLoaders: 1 }
},
'postcss-loader'
]
})
2017-08-16 06:47:34 +02:00
},
{
2018-03-06 01:29:09 +01:00
// creates version.json for /__version__ from package.json
test: require.resolve('./package.json'),
2017-08-16 06:47:34 +02:00
use: [
{
loader: 'file-loader',
2017-08-16 06:47:34 +02:00
options: {
name: 'version.json'
2017-08-16 06:47:34 +02:00
}
},
'extract-loader',
'./build/package_json_loader'
]
},
{
2018-03-06 01:29:09 +01:00
// creates a js script for each ftl
test: /\.ftl$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[hash:8].js'
}
},
'extract-loader',
'./build/fluent_loader'
2017-08-16 06:47:34 +02:00
]
},
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
test: require.resolve('./build/generate_asset_map.js'),
use: ['babel-loader', 'val-loader']
},
{
2018-03-06 01:29:09 +01:00
// loads all the ftl from public/locales for use by common/locales.js
test: require.resolve('./build/generate_l10n_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: [
new CopyPlugin([
{
context: 'public',
from: '*.*'
}
]),
2018-03-06 01:29:09 +01:00
new webpack.IgnorePlugin(/dist/), // used in common/*.js
new webpack.IgnorePlugin(/require-from-string/), // used in common/locales.js
2017-08-16 06:47:34 +02:00
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
2017-08-26 00:12:16 +02:00
name: 'vendor',
minChunks: ({ resource }) => /node_modules/.test(resource)
2017-08-16 06:47:34 +02:00
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'runtime'
}),
2018-02-20 08:43:15 +01:00
new ExtractTextPlugin({
filename: 'style.[contenthash:8].css'
}),
2018-03-06 01:29:09 +01:00
new ManifestPlugin() // used by server side to resolve hashed assets
],
devServer: {
compress: true,
host: '0.0.0.0',
before: IS_DEV ? require('./server/dev') : undefined
}
2017-08-07 04:32:07 +02:00
};