2017-08-07 02:32:07 +00:00
|
|
|
const path = require('path');
|
2017-08-16 04:47:34 +00:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2017-08-24 21:54:02 +00:00
|
|
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
2018-07-12 20:13:49 +00:00
|
|
|
const VersionPlugin = require('./build/version_plugin');
|
2018-07-13 18:13:09 +00:00
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
2017-08-07 02:32:07 +00:00
|
|
|
|
2018-07-12 20:13:49 +00:00
|
|
|
const webJsOptions = {
|
2017-12-05 20:45:36 +00:00
|
|
|
babelrc: false,
|
2018-09-07 05:52:10 +00:00
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
useBuiltIns: 'entry'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
],
|
2018-03-06 00:29:09 +00:00
|
|
|
// yo-yoify converts html template strings to direct dom api calls
|
2018-09-07 05:52:10 +00:00
|
|
|
plugins: [
|
|
|
|
'yo-yoify',
|
|
|
|
['@babel/plugin-proposal-class-properties', { loose: false }]
|
|
|
|
]
|
2017-12-05 20:45:36 +00:00
|
|
|
};
|
|
|
|
|
2018-07-13 03:48:07 +00:00
|
|
|
const serviceWorker = {
|
|
|
|
target: 'webworker',
|
|
|
|
entry: {
|
|
|
|
serviceWorker: './app/serviceWorker.js'
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
path: path.resolve(__dirname, 'dist'),
|
|
|
|
publicPath: '/'
|
2018-07-13 18:36:51 +00:00
|
|
|
},
|
|
|
|
devtool: 'source-map'
|
2018-07-13 03:48:07 +00:00
|
|
|
};
|
|
|
|
|
2018-07-12 20:13:49 +00:00
|
|
|
const web = {
|
|
|
|
target: 'web',
|
|
|
|
entry: {
|
|
|
|
// babel-polyfill and fluent are directly included in vendor
|
|
|
|
// because they are not explicitly referenced by app
|
2018-09-07 05:52:10 +00:00
|
|
|
vendor: ['@babel/polyfill', 'fluent'], //TODO: remove @babel/polyfill
|
2018-07-27 13:11:46 +00:00
|
|
|
app: ['./app/main.js'],
|
2018-07-27 13:20:08 +00:00
|
|
|
android: ['./android/android.js'],
|
|
|
|
ios: ['./ios/ios.js']
|
2018-07-12 20:13:49 +00:00
|
|
|
},
|
2017-08-07 02:32:07 +00:00
|
|
|
output: {
|
2018-07-12 20:13:49 +00:00
|
|
|
filename: '[name].[hash:8].js',
|
2017-08-24 21:54:02 +00:00
|
|
|
path: path.resolve(__dirname, 'dist'),
|
2017-08-10 02:22:20 +00:00
|
|
|
publicPath: '/'
|
2017-08-07 02:32:07 +00:00
|
|
|
},
|
|
|
|
module: {
|
2017-08-14 19:04:03 +00:00
|
|
|
rules: [
|
2017-08-07 02:32:07 +00:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
2017-08-25 22:38:26 +00:00
|
|
|
oneOf: [
|
|
|
|
{
|
2018-07-05 19:40:49 +00:00
|
|
|
include: [require.resolve('./assets/cryptofill')],
|
2017-08-25 22:38:26 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[hash:8].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-08-24 21:54:02 +00:00
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// fluent gets exposed as a global so that each language script
|
|
|
|
// can load independently and share it.
|
2017-08-25 22:38:26 +00:00
|
|
|
include: [path.dirname(require.resolve('fluent'))],
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'expose-loader',
|
|
|
|
options: 'fluent'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
2018-09-07 05:52:10 +00:00
|
|
|
options: webJsOptions
|
2017-08-25 22:38:26 +00:00
|
|
|
}
|
|
|
|
]
|
2017-08-24 21:54:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
2017-08-25 22:38:26 +00:00
|
|
|
include: [
|
|
|
|
path.resolve(__dirname, 'app'),
|
|
|
|
path.resolve(__dirname, 'common'),
|
2018-03-06 00:29:09 +00:00
|
|
|
// some dependencies need to get re-babeled because we
|
|
|
|
// have different targets than their default configs
|
2017-11-30 21:41:09 +00: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-25 22:38:26 +00:00
|
|
|
],
|
2018-07-12 20:13:49 +00:00
|
|
|
options: webJsOptions
|
2017-08-25 22:38:26 +00:00
|
|
|
},
|
2017-08-24 21:54:02 +00:00
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// Strip asserts from our deps, mainly choojs family
|
2017-08-25 22:38:26 +00:00
|
|
|
include: [path.resolve(__dirname, 'node_modules')],
|
2018-07-31 18:29:26 +00:00
|
|
|
exclude: [path.resolve(__dirname, 'node_modules/crc')],
|
2017-08-25 22:38:26 +00:00
|
|
|
loader: 'webpack-unassert-loader'
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-08-16 04:47:34 +00:00
|
|
|
{
|
2018-02-26 19:48:28 +00:00
|
|
|
test: /\.(png|jpg)$/,
|
2017-08-16 04:47:34 +00:00
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
2017-08-24 21:54:02 +00:00
|
|
|
name: '[name].[hash:8].[ext]'
|
2017-08-16 04:47:34 +00:00
|
|
|
}
|
|
|
|
},
|
2018-02-26 19:48:28 +00:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[hash:8].[ext]'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'svgo-loader',
|
|
|
|
options: {
|
2018-02-27 04:28:51 +00:00
|
|
|
plugins: [
|
2018-03-06 00:29:09 +00:00
|
|
|
{ removeViewBox: false }, // true causes stretched images
|
|
|
|
{ convertStyleToAttrs: true }, // for CSP, no unsafe-eval
|
|
|
|
{ removeTitle: true } // for smallness
|
2018-02-27 04:28:51 +00:00
|
|
|
]
|
2018-02-26 19:48:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-08-16 04:47:34 +00:00
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// creates style.css with all styles
|
2017-08-16 04:47:34 +00:00
|
|
|
test: /\.css$/,
|
2018-07-13 18:13:09 +00:00
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'postcss-loader'
|
|
|
|
]
|
|
|
|
})
|
2017-08-24 21:54:02 +00:00
|
|
|
},
|
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// creates a js script for each ftl
|
2017-08-24 21:54:02 +00:00
|
|
|
test: /\.ftl$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[path][name].[hash:8].js'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'extract-loader',
|
2018-07-12 20:13:49 +00:00
|
|
|
'babel-loader',
|
2017-08-24 21:54:02 +00:00
|
|
|
'./build/fluent_loader'
|
2017-08-16 04:47:34 +00:00
|
|
|
]
|
2017-08-24 21:54:02 +00:00
|
|
|
},
|
2018-02-21 04:31:27 +00:00
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// creates test.js for /test
|
2018-02-21 04:31:27 +00:00
|
|
|
test: require.resolve('./test/frontend/index.js'),
|
|
|
|
use: ['babel-loader', 'val-loader']
|
|
|
|
},
|
2017-08-24 21:54:02 +00:00
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// loads all assets from assets/ for use by common/assets.js
|
2017-08-24 21:54:02 +00:00
|
|
|
test: require.resolve('./build/generate_asset_map.js'),
|
|
|
|
use: ['babel-loader', 'val-loader']
|
|
|
|
},
|
|
|
|
{
|
2018-03-06 00:29:09 +00:00
|
|
|
// loads all the ftl from public/locales for use by common/locales.js
|
2017-08-24 21:54:02 +00:00
|
|
|
test: require.resolve('./build/generate_l10n_map.js'),
|
|
|
|
use: ['babel-loader', 'val-loader']
|
2017-08-07 02:32:07 +00:00
|
|
|
}
|
|
|
|
]
|
2017-08-15 18:55:52 +00:00
|
|
|
},
|
2017-08-16 04:47:34 +00:00
|
|
|
plugins: [
|
|
|
|
new CopyPlugin([
|
|
|
|
{
|
|
|
|
context: 'public',
|
|
|
|
from: '*.*'
|
2018-09-07 17:08:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
context: 'android/app/src/main/assets',
|
|
|
|
from: '*.*',
|
|
|
|
to: 'android_asset'
|
2017-08-16 04:47:34 +00:00
|
|
|
}
|
|
|
|
]),
|
2018-08-07 22:40:17 +00:00
|
|
|
new webpack.IgnorePlugin(/\.\.\/dist/), // used in common/*.js
|
2018-03-06 00:29:09 +00:00
|
|
|
new webpack.IgnorePlugin(/require-from-string/), // used in common/locales.js
|
2017-08-16 04:47:34 +00:00
|
|
|
new webpack.HashedModuleIdsPlugin(),
|
2018-07-13 18:13:09 +00:00
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: '[name].[hash:8].css'
|
2018-02-20 07:43:15 +00:00
|
|
|
}),
|
2018-07-12 20:13:49 +00:00
|
|
|
new VersionPlugin(),
|
2018-03-06 00:29:09 +00:00
|
|
|
new ManifestPlugin() // used by server side to resolve hashed assets
|
2017-08-24 21:54:02 +00:00
|
|
|
],
|
2018-07-13 18:36:51 +00:00
|
|
|
devtool: 'source-map',
|
2017-08-24 21:54:02 +00:00
|
|
|
devServer: {
|
2018-07-13 18:13:09 +00:00
|
|
|
before: require('./server/bin/dev'),
|
2017-08-24 21:54:02 +00:00
|
|
|
compress: true,
|
2018-07-12 20:13:49 +00:00
|
|
|
hot: false,
|
2018-03-01 03:24:41 +00:00
|
|
|
host: '0.0.0.0',
|
2018-06-21 00:05:33 +00:00
|
|
|
proxy: {
|
|
|
|
'/api/ws': {
|
|
|
|
target: 'ws://localhost:8081',
|
|
|
|
ws: true,
|
|
|
|
secure: false
|
|
|
|
}
|
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
2017-08-07 02:32:07 +00:00
|
|
|
};
|
2018-07-12 20:13:49 +00:00
|
|
|
|
2018-07-13 18:13:09 +00:00
|
|
|
module.exports = (env, argv) => {
|
|
|
|
const mode = argv.mode || 'production';
|
2018-07-12 20:13:49 +00:00
|
|
|
console.error(`mode: ${mode}`);
|
|
|
|
web.mode = serviceWorker.mode = mode;
|
|
|
|
if (mode === 'development') {
|
|
|
|
// istanbul instruments the source for code coverage
|
|
|
|
webJsOptions.plugins.push('istanbul');
|
2018-07-13 03:48:07 +00:00
|
|
|
web.entry.tests = ['./test/frontend/index.js'];
|
2018-07-12 20:13:49 +00:00
|
|
|
}
|
2018-07-13 18:13:09 +00:00
|
|
|
return [web, serviceWorker];
|
2018-07-13 03:48:07 +00:00
|
|
|
};
|