2020-11-25 20:16:45 +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');
|
|
|
|
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const WorkboxPlugin = require('workbox-webpack-plugin');
|
|
|
|
|
|
|
|
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';
|
2020-12-10 13:15:41 +00:00
|
|
|
const editor = process.env.TARGET_EDITOR == 'cell' ? 'spreadsheeteditor' :
|
|
|
|
process.env.TARGET_EDITOR == 'slide' ? 'presentationeditor' : 'documenteditor';
|
2020-11-25 20:16:45 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mode: env,
|
|
|
|
entry: {
|
2020-12-10 13:15:41 +00:00
|
|
|
app: `../../apps/${editor}/mobile/src/app.js`,
|
2020-11-25 20:16:45 +00:00
|
|
|
},
|
|
|
|
output: {
|
2020-12-10 13:15:41 +00:00
|
|
|
path: resolvePath(`../../apps/${editor}/mobile`), // path above depends on it
|
2020-11-25 20:16:45 +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: {
|
2020-12-10 13:15:41 +00:00
|
|
|
'@': resolvePath(`../../apps/${editor}/mobile/src`),
|
2020-11-25 20:16:45 +00:00
|
|
|
},
|
|
|
|
modules: [path.resolve(__dirname, '..', 'node_modules'), 'node_modules'],
|
|
|
|
},
|
|
|
|
watch: true,
|
|
|
|
watchOptions: {
|
|
|
|
aggregateTimeout: 600,
|
|
|
|
poll: 1000,
|
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
jquery: 'jQuery'
|
|
|
|
},
|
|
|
|
|
|
|
|
devtool: env === 'production' ? 'source-map' : 'source-map',
|
|
|
|
optimization: {
|
|
|
|
minimizer: [new TerserPlugin({
|
|
|
|
sourceMap: true,
|
|
|
|
})],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(mjs|js|jsx)$/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
include: [
|
2020-12-10 13:15:41 +00:00
|
|
|
resolvePath(`../../apps/${editor}/mobile/src`),
|
2020-11-25 20:16:45 +00:00
|
|
|
resolvePath('../../apps/common/mobile/lib'),
|
|
|
|
resolvePath('node_modules/framework7'),
|
|
|
|
|
|
|
|
resolvePath('node_modules/framework7-react'),
|
|
|
|
|
|
|
|
resolvePath('node_modules/template7'),
|
|
|
|
resolvePath('node_modules/dom7'),
|
|
|
|
resolvePath('node_modules/ssr-window'),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
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: '../'
|
|
|
|
}
|
|
|
|
}),
|
2020-12-10 13:15:41 +00:00
|
|
|
'css-loader',
|
2020-11-25 20:16:45 +00:00
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: path.resolve(__dirname, '..'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-12-10 13:15:41 +00:00
|
|
|
{
|
|
|
|
loader: "less-loader",
|
|
|
|
options: {
|
|
|
|
lessOptions: {
|
|
|
|
javascriptEnabled: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-11-25 20:16:45 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10000,
|
|
|
|
name: 'images/[name].[ext]',
|
2020-12-10 13:15:41 +00:00
|
|
|
outputPath: `../../../apps/${editor}/mobile/dist`,
|
2020-11-25 20:16:45 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10000,
|
|
|
|
name: 'fonts/[name].[ext]',
|
2020-12-10 13:15:41 +00:00
|
|
|
outputPath: `../../../apps/${editor}/mobile/dist/assets`,
|
2020-11-25 20:16:45 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(env),
|
|
|
|
'process.env.TARGET': JSON.stringify(target),
|
|
|
|
}),
|
|
|
|
|
|
|
|
...(env === 'production' ? [
|
|
|
|
new OptimizeCSSPlugin({
|
|
|
|
cssProcessorOptions: {
|
|
|
|
safe: true,
|
|
|
|
map: { inline: false },
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
|
|
|
] : [
|
|
|
|
// Development only plugins
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
new webpack.NamedModulesPlugin(),
|
|
|
|
]),
|
|
|
|
// new CleanWebpackPlugin(),
|
|
|
|
new HtmlWebpackPlugin({
|
2020-12-10 13:15:41 +00:00
|
|
|
filename: `../../../apps/${editor}/mobile/index.html`,
|
|
|
|
template: `../../apps/${editor}/mobile/src/index_dev.html`,
|
2020-11-25 20:16:45 +00:00
|
|
|
inject: true,
|
|
|
|
minify: env === 'production' ? {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeComments: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
useShortDoctype: true
|
|
|
|
} : false,
|
|
|
|
}),
|
|
|
|
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'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|