2017-02-26 17:51:38 +00:00
|
|
|
/**
|
|
|
|
* webpack config
|
|
|
|
*/
|
|
|
|
|
2017-02-19 06:54:19 +00:00
|
|
|
import * as webpack from 'webpack';
|
|
|
|
const StringReplacePlugin = require('string-replace-webpack-plugin');
|
2017-03-17 15:02:41 +00:00
|
|
|
import getVersion from './src/version';
|
2017-02-22 01:49:11 +00:00
|
|
|
const constants = require('./src/const.json');
|
|
|
|
|
2017-02-26 17:51:38 +00:00
|
|
|
const env = process.env.NODE_ENV;
|
|
|
|
const isProduction = env === 'production';
|
2017-02-19 06:54:19 +00:00
|
|
|
|
2017-03-17 15:02:41 +00:00
|
|
|
module.exports = new Promise(async resolve => {
|
|
|
|
const version = await getVersion.then();
|
|
|
|
|
|
|
|
const pack: webpack.Configuration = {
|
|
|
|
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',
|
|
|
|
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 06:54:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-17 15:02:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.styl$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{ loader: 'style-loader' },
|
|
|
|
{ loader: 'css-loader' },
|
|
|
|
{ loader: 'stylus-loader' }
|
|
|
|
]
|
2017-02-19 06:54:19 +00:00
|
|
|
}
|
2017-03-17 15:02:41 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
VERSION: JSON.stringify(version),
|
|
|
|
CONFIG: {
|
|
|
|
themeColor: JSON.stringify(constants.themeColor)
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new StringReplacePlugin()
|
|
|
|
],
|
|
|
|
output: {
|
|
|
|
filename: `[name]/script.${version}.js`
|
|
|
|
}
|
|
|
|
};
|
2017-02-26 17:51:38 +00:00
|
|
|
|
2017-03-17 15:02:41 +00:00
|
|
|
if (isProduction) {
|
|
|
|
//pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
|
|
|
|
}
|
2017-02-26 17:51:38 +00:00
|
|
|
|
2017-03-17 15:02:41 +00:00
|
|
|
resolve(pack);
|
|
|
|
});
|