1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-11-30 15:58:24 +09:00
misskey/webpack.config.ts

121 lines
2.8 KiB
TypeScript
Raw Normal View History

2017-02-27 02:51:38 +09:00
/**
* webpack config
*/
2017-03-31 01:02:37 +09:00
import * as fs from 'fs';
2017-02-19 15:54:19 +09:00
import * as webpack from 'webpack';
const StringReplacePlugin = require('string-replace-webpack-plugin');
2017-03-31 01:02:37 +09:00
import * as yaml from 'js-yaml';
2017-03-23 05:53:09 +09:00
2017-03-23 00:41:11 +09:00
import version from './src/version';
2017-02-22 10:49:11 +09:00
const constants = require('./src/const.json');
2017-04-01 04:41:44 +09:00
const languages = {
2017-03-31 01:25:09 +09:00
'en': yaml.safeLoad(fs.readFileSync('./locales/en.yml', 'utf-8')),
'ja': yaml.safeLoad(fs.readFileSync('./locales/ja.yml', 'utf-8'))
2017-03-23 05:53:09 +09:00
};
2017-04-01 04:40:52 +09:00
const native = languages.ja;
2017-02-27 02:51:38 +09:00
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
2017-02-19 15:54:19 +09:00
2017-03-23 05:53:09 +09:00
module.exports = (Object as any).entries(languages).map(([lang, locale]) => {
locale = Object.assign({}, native, locale);
2017-04-01 04:40:52 +09:00
2017-03-23 05:53:09 +09:00
const pack /*: webpack.Configuration ← fuck wrong type definition!!! */ = {
name: lang,
entry: {
'desktop': './src/web/app/desktop/script.js',
'mobile': './src/web/app/mobile/script.js',
'dev': './src/web/app/dev/script.js',
'auth': './src/web/app/auth/script.js'
},
module: {
rules: [
{
enforce: 'pre',
2017-03-23 06:31:46 +09:00
test: /\.(tag|js)$/,
2017-03-23 05:53:09 +09:00
exclude: /node_modules/,
loader: StringReplacePlugin.replace({
replacements: [
2017-03-31 01:25:09 +09:00
{
pattern: /%i18n:(.+?)%/g, replacement: (_, key) => {
let text = locale;
const error = key.split('.').some(k => {
if (text.hasOwnProperty(k)) {
text = text[k];
return false;
} else {
return true;
}
});
if (error) {
console.warn(`key '${key}' not found in '${lang}'`);
2017-04-01 04:40:52 +09:00
return key;
2017-03-26 03:23:19 +09:00
} else {
2017-03-31 01:25:09 +09:00
return text.replace(/'/g, '\\\'').replace(/"/g, '\\"');
2017-03-26 03:23:19 +09:00
}
}
2017-03-31 01:25:09 +09:00
}
2017-03-23 05:53:09 +09:00
]
})
},
{
enforce: 'pre',
test: /\.tag$/,
exclude: /node_modules/,
loader: StringReplacePlugin.replace({
replacements: [
{ pattern: /\$theme\-color\-foreground/g, replacement: () => constants.themeColorForeground },
{ pattern: /\$theme\-color/g, replacement: () => constants.themeColor },
]
})
},
{
test: /\.tag$/,
exclude: /node_modules/,
loader: 'riot-tag-loader',
query: {
hot: false,
style: 'stylus',
expr: false,
compact: true,
parserOptions: {
style: {
compress: true
}
2017-02-19 15:54:19 +09:00
}
}
2017-03-23 05:53:09 +09:00
},
{
test: /\.styl$/,
exclude: /node_modules/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'stylus-loader' }
]
2017-02-19 15:54:19 +09:00
}
2017-03-23 05:53:09 +09:00
]
},
plugins: [
new webpack.DefinePlugin({
VERSION: JSON.stringify(version),
THEME_COLOR: JSON.stringify(constants.themeColor)
}),
new StringReplacePlugin()
],
output: {
path: __dirname + '/built/web/assets',
2017-03-23 19:00:04 +09:00
filename: `[name].${version}.${lang}.js`
2017-03-23 05:53:09 +09:00
}
};
2017-03-23 00:41:11 +09:00
2017-03-23 05:53:09 +09:00
if (isProduction) {
//pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
}
2017-02-27 02:51:38 +09:00
2017-03-23 05:53:09 +09:00
return pack;
});