paricafe/webpack/webpack.config.ts

140 lines
3 KiB
TypeScript
Raw Normal View History

2017-05-16 10:00:56 -05:00
/**
* webpack configuration
*/
2018-02-18 00:27:06 -06:00
const minify = require('html-minifier').minify;
2018-02-15 12:23:10 -06: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 10:00:56 -05:00
import plugins from './plugins';
2017-12-16 13:02:30 -06:00
import langs from '../locales';
2017-05-16 10:00:56 -05:00
import version from '../src/version';
2018-02-15 12:23:10 -06:00
global['faReplacement'] = faReplacement;
2018-02-18 00:27:06 -06:00
global['collapseSpacesReplacement'] = html => {
return minify(html, {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
keepClosingSlash: true
});
};
2017-12-16 23:35:30 -06:00
module.exports = Object.keys(langs).map(lang => {
2017-05-16 10:00:56 -05:00
// Chunk name
const name = lang;
// Entries
const entry = {
2017-11-13 03:05:35 -06:00
desktop: './src/web/app/desktop/script.ts',
2018-02-09 19:27:05 -06:00
//mobile: './src/web/app/mobile/script.ts',
//ch: './src/web/app/ch/script.ts',
//stats: './src/web/app/stats/script.ts',
//status: './src/web/app/status/script.ts',
//dev: './src/web/app/dev/script.ts',
//auth: './src/web/app/auth/script.ts',
2017-11-20 14:09:45 -06:00
sw: './src/web/app/sw.js'
2017-05-16 10:00:56 -05:00
};
const output = {
path: __dirname + '/../built/web/assets',
filename: `[name].${version}.${lang}.js`
};
2018-02-15 12:23:10 -06:00
const i18nReplacer = new I18nReplacer(lang);
global['i18nReplacement'] = i18nReplacer.replacement;
2017-05-16 10:00:56 -05:00
return {
name,
entry,
2018-02-15 12:23:10 -06:00
module: {
rules: [{
test: /\.vue$/,
exclude: /node_modules/,
2018-02-18 00:27:06 -06:00
use: [/*'cache-loader', */{
2018-02-15 12:23:10 -06:00
loader: 'vue-loader',
options: {
cssSourceMap: false,
preserveWhitespace: false
}
}, {
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-18 00:27:06 -06:00
}, {
loader: 'replace',
query: {
search: /^<template>([\s\S]+?)\r?\n<\/template>/.toString(),
replace: 'collapseSpacesReplacement'
}
2018-02-15 12:23:10 -06:00
}]
}, {
test: /\.styl$/,
exclude: /node_modules/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'stylus-loader' }
]
}, {
test: /\.ts$/,
exclude: /node_modules/,
2018-02-15 12:26:59 -06:00
use: [{
loader: 'ts-loader',
options: {
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 12:23:10 -06:00
}]
},
2017-11-03 03:46:42 -05:00
plugins: plugins(version, lang),
2017-11-13 03:05:35 -06:00
output,
resolve: {
extensions: [
'.js', '.ts'
]
2018-02-14 22:18:34 -06:00
},
2018-02-15 11:53:54 -06:00
resolveLoader: {
modules: ['node_modules', './webpack/loaders']
},
2018-02-16 12:01:00 -06:00
cache: true
2017-05-16 10:00:56 -05:00
};
});