2020-08-13 10:39:46 +00:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
|
|
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2021-03-22 08:42:10 +00:00
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
2020-08-13 10:39:46 +00:00
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const WorkboxPlugin = require('workbox-webpack-plugin');
|
2021-03-27 21:28:07 +00:00
|
|
|
const fs = require('fs')
|
2020-08-13 10:39:46 +00:00
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
function resolvePath(dir) {
|
|
|
|
return path.join(__dirname, '..', dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
const env = process.env.NODE_ENV || 'development';
|
|
|
|
const target = process.env.TARGET || 'web';
|
2021-03-11 07:18:13 +00:00
|
|
|
const editor = process.env.TARGET_EDITOR == 'cell' ? 'spreadsheeteditor' :
|
|
|
|
process.env.TARGET_EDITOR == 'slide' ? 'presentationeditor' : 'documenteditor';
|
2021-03-27 21:28:07 +00:00
|
|
|
const targetPatch = process.env.TARGET_EDITOR || 'word';
|
2021-08-02 14:31:03 +00:00
|
|
|
const addonPath = process.env.ADDON_ENV || 'path';
|
2020-08-13 10:39:46 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mode: env,
|
|
|
|
entry: {
|
2021-03-11 07:18:13 +00:00
|
|
|
app: `../../apps/${editor}/mobile/src/app.js`,
|
2020-08-13 10:39:46 +00:00
|
|
|
},
|
|
|
|
output: {
|
2021-03-11 07:18:13 +00:00
|
|
|
path: resolvePath(`../../apps/${editor}/mobile`), // path above depends on it
|
2020-08-13 10:39:46 +00:00
|
|
|
filename: 'dist/js/[name].js', // in such form will be injected in index.html
|
|
|
|
chunkFilename: 'dist/js/[name].js',
|
|
|
|
publicPath: '',
|
|
|
|
hotUpdateChunkFilename: 'hot/hot-update.js',
|
|
|
|
hotUpdateMainFilename: 'hot/hot-update.json',
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.json'],
|
|
|
|
alias: {
|
2021-03-11 07:18:13 +00:00
|
|
|
'@': resolvePath(`../../apps/${editor}/mobile/src`),
|
2020-08-13 10:39:46 +00:00
|
|
|
},
|
|
|
|
modules: [path.resolve(__dirname, '..', 'node_modules'), 'node_modules'],
|
|
|
|
},
|
2021-04-16 12:47:06 +00:00
|
|
|
watch: env == 'development',
|
2020-08-13 10:39:46 +00:00
|
|
|
watchOptions: {
|
|
|
|
aggregateTimeout: 600,
|
|
|
|
poll: 1000,
|
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
jquery: 'jQuery'
|
|
|
|
},
|
|
|
|
|
2021-10-23 08:35:46 +00:00
|
|
|
devtool: env === 'production' ? false/*'source-map'*/ : 'source-map', // TODO: turn off debugger source map before release
|
2020-08-13 10:39:46 +00:00
|
|
|
optimization: {
|
|
|
|
minimizer: [new TerserPlugin({
|
|
|
|
})],
|
2021-03-22 08:42:10 +00:00
|
|
|
moduleIds: 'named',
|
2020-08-13 10:39:46 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(mjs|js|jsx)$/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
include: [
|
2021-03-11 07:18:13 +00:00
|
|
|
resolvePath(`../../apps/${editor}/mobile/src`),
|
2020-08-31 17:31:05 +00:00
|
|
|
resolvePath('../../apps/common/mobile/lib'),
|
2020-08-13 10:39:46 +00:00
|
|
|
resolvePath('node_modules/framework7'),
|
|
|
|
|
|
|
|
resolvePath('node_modules/framework7-react'),
|
|
|
|
|
|
|
|
resolvePath('node_modules/template7'),
|
|
|
|
resolvePath('node_modules/dom7'),
|
|
|
|
resolvePath('node_modules/ssr-window'),
|
2021-04-03 15:38:32 +00:00
|
|
|
|
2021-08-02 18:31:49 +00:00
|
|
|
//resolvePath(`${addonPath}`),
|
|
|
|
resolvePath('../../../web-apps-mobile/word'),
|
|
|
|
resolvePath('../../../web-apps-mobile/slide'),
|
|
|
|
resolvePath('../../../web-apps-mobile/cell')
|
2020-08-13 10:39:46 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
(env === 'development' ? 'style-loader' : {
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
|
|
|
publicPath: '../'
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: path.resolve(__dirname, '..'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.less$/,
|
|
|
|
use: [
|
|
|
|
(env === 'development' ? 'style-loader' : {
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
|
|
|
publicPath: '../'
|
|
|
|
}
|
|
|
|
}),
|
2021-10-22 20:03:03 +00:00
|
|
|
'css-loader?url=false',
|
2020-08-13 10:39:46 +00:00
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: path.resolve(__dirname, '..'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-03-11 07:18:13 +00:00
|
|
|
{
|
|
|
|
loader: "less-loader",
|
|
|
|
options: {
|
|
|
|
lessOptions: {
|
2021-10-22 20:03:03 +00:00
|
|
|
javascriptEnabled: true,
|
|
|
|
globalVars: {
|
|
|
|
"common-image-header-path": env === 'production' ? `../../../${editor}/mobile/resources/img/header` : '../../common/mobile/resources/img/header',
|
|
|
|
"common-image-about-path": env === 'production' ? `../../../${editor}/mobile/resources/img/about` : '../../common/main/resources/img/about',
|
|
|
|
}
|
2021-03-11 07:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-08-13 10:39:46 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10000,
|
|
|
|
name: 'images/[name].[ext]',
|
2021-03-11 07:18:13 +00:00
|
|
|
outputPath: `../../../apps/${editor}/mobile/dist`,
|
2020-08-13 10:39:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10000,
|
|
|
|
name: 'fonts/[name].[ext]',
|
2021-03-11 07:18:13 +00:00
|
|
|
outputPath: `../../../apps/${editor}/mobile/dist/assets`,
|
2020-08-13 10:39:46 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(env),
|
|
|
|
'process.env.TARGET': JSON.stringify(target),
|
2021-04-20 09:47:57 +00:00
|
|
|
__PRODUCT_VERSION__: JSON.stringify(process.env.PRODUCT_VERSION ? process.env.PRODUCT_VERSION : '6.2.0d'),
|
2021-10-23 08:35:46 +00:00
|
|
|
__PUBLISHER_ADDRESS__: JSON.stringify(process.env.PUBLISHER_ADDRESS || '20A-12 Ernesta Birznieka-Upisha street, Riga, Latvia, EU, LV-1050'),
|
|
|
|
__SUPPORT_EMAIL__: JSON.stringify(process.env.SUPPORT_EMAIL || 'support@onlyoffice.com'),
|
|
|
|
__PUBLISHER_PHONE__: JSON.stringify(process.env.PUBLISHER_PHONE || '+371 633-99867'),
|
|
|
|
__PUBLISHER_URL__: JSON.stringify(process.env.PUBLISHER_URL || 'https://www.onlyoffice.com'),
|
|
|
|
__PUBLISHER_NAME__: JSON.stringify(process.env.PUBLISHER_NAME || 'Ascensio System SIA'),
|
2021-04-12 12:10:14 +00:00
|
|
|
__APP_TITLE_TEXT__: JSON.stringify(process.env.APP_TITLE_TEXT ? process.env.APP_TITLE_TEXT : 'ONLYOFFICE'),
|
2021-04-15 10:26:46 +00:00
|
|
|
__COMPANY_NAME__: JSON.stringify(process.env.COMPANY_NAME ? process.env.COMPANY_NAME : 'ONLYOFFICE'),
|
2021-10-23 08:35:46 +00:00
|
|
|
__HELP_URL__: JSON.stringify(process.env.HELP_URL || 'https://helpcenter.onlyoffice.com')
|
2020-08-13 10:39:46 +00:00
|
|
|
}),
|
2021-05-20 16:22:13 +00:00
|
|
|
new webpack.BannerPlugin(`\n* Version: ${process.env.PRODUCT_VERSION} (build: ${process.env.BUILD_NUMBER})\n`),
|
2020-08-13 10:39:46 +00:00
|
|
|
|
|
|
|
...(env === 'production' ? [
|
2021-03-22 08:42:10 +00:00
|
|
|
new CssMinimizerPlugin({
|
2021-04-08 14:54:03 +00:00
|
|
|
minimizerOptions: {
|
|
|
|
processorOptions: {
|
|
|
|
safe: true,
|
|
|
|
map: { inline: false },
|
|
|
|
},
|
2020-08-13 10:39:46 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
|
|
|
] : [
|
|
|
|
// Development only plugins
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
2021-03-22 08:42:10 +00:00
|
|
|
// new webpack.NamedModulesPlugin(),
|
2020-08-13 10:39:46 +00:00
|
|
|
]),
|
|
|
|
// new CleanWebpackPlugin(),
|
|
|
|
new HtmlWebpackPlugin({
|
2021-03-11 07:18:13 +00:00
|
|
|
filename: `../../../apps/${editor}/mobile/index.html`,
|
2021-05-06 11:14:51 +00:00
|
|
|
template: `../../apps/${editor}/mobile/src/index_dev.html`,
|
2020-08-13 10:39:46 +00:00
|
|
|
inject: true,
|
|
|
|
minify: env === 'production' ? {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeComments: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
useShortDoctype: true
|
|
|
|
} : false,
|
2021-10-22 20:04:06 +00:00
|
|
|
system: {
|
|
|
|
env: {
|
|
|
|
defaultLang: JSON.stringify(process.env.DEFAULT_LANG || "en"),
|
|
|
|
}
|
|
|
|
},
|
2020-08-13 10:39:46 +00:00
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'css/[name].css',
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
noErrorOnMissing: true,
|
|
|
|
from: resolvePath('src/static'),
|
|
|
|
to: resolvePath('www/static'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
noErrorOnMissing: true,
|
|
|
|
from: resolvePath('src/manifest.json'),
|
|
|
|
to: resolvePath('www/manifest.json'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-03-27 21:28:07 +00:00
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/\.{2}\/lib\/patch/,
|
2021-08-02 18:31:49 +00:00
|
|
|
resource => fs.existsSync(`../../../web-apps-mobile/${targetPatch}/patch.jsx`) ?
|
|
|
|
resource.request = `../../../../../../web-apps-mobile/${targetPatch}/patch.jsx` : resource
|
|
|
|
//resource => fs.existsSync(`${addonPath}/patch.jsx`) ?
|
|
|
|
//resource.request = `../../../${addonPath}/patch.jsx` : resource
|
2021-03-27 21:28:07 +00:00
|
|
|
),
|
2020-08-13 10:39:46 +00:00
|
|
|
],
|
|
|
|
};
|