2017-05-16 08:00:56 -07:00
|
|
|
/**
|
|
|
|
* webpack configuration
|
|
|
|
*/
|
|
|
|
|
2018-02-21 12:05:19 -08:00
|
|
|
import * as fs from 'fs';
|
2018-03-01 13:26:31 -08:00
|
|
|
import jsonImporter from 'node-sass-json-importer';
|
2018-02-17 22:27:06 -08:00
|
|
|
const minify = require('html-minifier').minify;
|
2018-02-15 10:23:10 -08:00
|
|
|
import I18nReplacer from '../src/common/build/i18n';
|
|
|
|
import { pattern as faPattern, replacement as faReplacement } from '../src/common/build/fa';
|
|
|
|
const constants = require('../src/const.json');
|
|
|
|
|
2017-05-16 08:00:56 -07:00
|
|
|
import plugins from './plugins';
|
|
|
|
|
2017-12-16 11:02:30 -08:00
|
|
|
import langs from '../locales';
|
2018-03-02 14:32:18 -08:00
|
|
|
const meta = require('../package.json');
|
|
|
|
const version = meta.version;
|
2017-05-16 08:00:56 -07:00
|
|
|
|
2018-02-15 10:23:10 -08:00
|
|
|
global['faReplacement'] = faReplacement;
|
|
|
|
|
2018-02-17 22:27:06 -08:00
|
|
|
global['collapseSpacesReplacement'] = html => {
|
|
|
|
return minify(html, {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
collapseInlineTagWhitespace: true,
|
|
|
|
keepClosingSlash: true
|
2018-02-21 12:05:19 -08:00
|
|
|
}).replace(/\t/g, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
global['base64replacement'] = (_, key) => {
|
|
|
|
return fs.readFileSync(__dirname + '/../src/web/' + key, 'base64');
|
2018-02-17 22:27:06 -08:00
|
|
|
};
|
|
|
|
|
2017-12-16 21:35:30 -08:00
|
|
|
module.exports = Object.keys(langs).map(lang => {
|
2017-05-16 08:00:56 -07:00
|
|
|
// Chunk name
|
|
|
|
const name = lang;
|
|
|
|
|
|
|
|
// Entries
|
|
|
|
const entry = {
|
2017-11-13 01:05:35 -08:00
|
|
|
desktop: './src/web/app/desktop/script.ts',
|
2018-02-21 09:00:30 -08:00
|
|
|
mobile: './src/web/app/mobile/script.ts',
|
2018-02-09 17:27:05 -08:00
|
|
|
//ch: './src/web/app/ch/script.ts',
|
|
|
|
//stats: './src/web/app/stats/script.ts',
|
|
|
|
//status: './src/web/app/status/script.ts',
|
2018-02-27 07:11:28 -08:00
|
|
|
dev: './src/web/app/dev/script.ts',
|
|
|
|
auth: './src/web/app/auth/script.ts',
|
2017-11-20 12:09:45 -08:00
|
|
|
sw: './src/web/app/sw.js'
|
2017-05-16 08:00:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const output = {
|
|
|
|
path: __dirname + '/../built/web/assets',
|
|
|
|
filename: `[name].${version}.${lang}.js`
|
|
|
|
};
|
|
|
|
|
2018-02-15 10:23:10 -08:00
|
|
|
const i18nReplacer = new I18nReplacer(lang);
|
|
|
|
global['i18nReplacement'] = i18nReplacer.replacement;
|
|
|
|
|
2017-05-16 08:00:56 -07:00
|
|
|
return {
|
|
|
|
name,
|
|
|
|
entry,
|
2018-02-15 10:23:10 -08:00
|
|
|
module: {
|
|
|
|
rules: [{
|
|
|
|
test: /\.vue$/,
|
|
|
|
exclude: /node_modules/,
|
2018-03-02 14:32:18 -08:00
|
|
|
use: ['cache-loader', {
|
2018-02-15 10:23:10 -08:00
|
|
|
loader: 'vue-loader',
|
|
|
|
options: {
|
|
|
|
cssSourceMap: false,
|
|
|
|
preserveWhitespace: false
|
|
|
|
}
|
2018-02-21 12:05:19 -08:00
|
|
|
}, {
|
|
|
|
loader: 'replace',
|
|
|
|
query: {
|
|
|
|
search: /%base64:(.+?)%/g.toString(),
|
|
|
|
replace: 'base64replacement'
|
|
|
|
}
|
2018-02-15 10:23:10 -08:00
|
|
|
}, {
|
|
|
|
loader: 'webpack-replace-loader',
|
|
|
|
options: {
|
|
|
|
search: '$theme-color',
|
|
|
|
replace: constants.themeColor,
|
|
|
|
attr: 'g'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
loader: 'webpack-replace-loader',
|
|
|
|
query: {
|
|
|
|
search: '$theme-color-foreground',
|
|
|
|
replace: constants.themeColorForeground,
|
|
|
|
attr: 'g'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
loader: 'replace',
|
|
|
|
query: {
|
|
|
|
search: i18nReplacer.pattern.toString(),
|
|
|
|
replace: 'i18nReplacement'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
loader: 'replace',
|
|
|
|
query: {
|
|
|
|
search: faPattern.toString(),
|
|
|
|
replace: 'faReplacement'
|
|
|
|
}
|
2018-02-17 22:27:06 -08:00
|
|
|
}, {
|
|
|
|
loader: 'replace',
|
|
|
|
query: {
|
|
|
|
search: /^<template>([\s\S]+?)\r?\n<\/template>/.toString(),
|
|
|
|
replace: 'collapseSpacesReplacement'
|
|
|
|
}
|
2018-02-15 10:23:10 -08:00
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
test: /\.styl$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{ loader: 'style-loader' },
|
|
|
|
{ loader: 'css-loader' },
|
|
|
|
{ loader: 'stylus-loader' }
|
|
|
|
]
|
2018-03-01 13:26:31 -08:00
|
|
|
}, {
|
|
|
|
test: /\.scss$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [{
|
|
|
|
loader: 'style-loader'
|
|
|
|
}, {
|
|
|
|
loader: 'css-loader'
|
|
|
|
}, {
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
importer: jsonImporter,
|
|
|
|
}
|
|
|
|
}]
|
2018-02-20 12:55:19 -08:00
|
|
|
}, {
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{ loader: 'style-loader' },
|
|
|
|
{ loader: 'css-loader' }
|
|
|
|
]
|
2018-03-01 13:26:31 -08:00
|
|
|
}, {
|
|
|
|
test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
|
|
|
|
loader: 'file-loader'
|
2018-02-15 10:23:10 -08:00
|
|
|
}, {
|
|
|
|
test: /\.ts$/,
|
|
|
|
exclude: /node_modules/,
|
2018-02-15 10:26:59 -08:00
|
|
|
use: [{
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
2018-03-02 14:32:18 -08:00
|
|
|
happyPackMode: true,
|
2018-02-15 10:26:59 -08:00
|
|
|
configFile: __dirname + '/../src/web/app/tsconfig.json',
|
|
|
|
appendTsSuffixTo: [/\.vue$/]
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
loader: 'replace',
|
|
|
|
query: {
|
|
|
|
search: i18nReplacer.pattern.toString(),
|
|
|
|
replace: 'i18nReplacement'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
loader: 'replace',
|
|
|
|
query: {
|
|
|
|
search: faPattern.toString(),
|
|
|
|
replace: 'faReplacement'
|
|
|
|
}
|
|
|
|
}]
|
2018-02-15 10:23:10 -08:00
|
|
|
}]
|
|
|
|
},
|
2017-11-03 01:46:42 -07:00
|
|
|
plugins: plugins(version, lang),
|
2017-11-13 01:05:35 -08:00
|
|
|
output,
|
|
|
|
resolve: {
|
|
|
|
extensions: [
|
2018-02-25 00:03:39 -08:00
|
|
|
'.js', '.ts', '.json'
|
2017-11-13 01:05:35 -08:00
|
|
|
]
|
2018-02-14 20:18:34 -08:00
|
|
|
},
|
2018-02-15 09:53:54 -08:00
|
|
|
resolveLoader: {
|
|
|
|
modules: ['node_modules', './webpack/loaders']
|
|
|
|
},
|
2018-02-16 10:01:00 -08:00
|
|
|
cache: true
|
2017-05-16 08:00:56 -07:00
|
|
|
};
|
|
|
|
});
|