mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 04:02:08 +08:00

* feat: image setting * opti: inline image * add imageSelectAction * remove axios from muya * update image selector * finish image selector ui * add load success style * delete image by click delete icon * opti structure of image html * handle arrow key * enter to edit * image preview by press space * handle backspace when the previous element is image wrapper * update codes for change another PC * emable select all in input * handle arrow and backspace key * create a new paragraph after the last paragraph if its not empty * handle backspace when the previous element is image wrapper * handle enter event in image selector * rewrite auto show image selector * modify image folder * copy file to folder * select image * handle paste image * picgo * guess image path from clipboard * drag and drop image to Mark Text * add github uploader * remove unused codes * remove unused codes * rewrite image path auto complete * support `path` imageInsertAction * doc: add image uploader doc * remove debug codes * set init value in image uploader page * fix typo * remove unused codes * drag web image to Mark Text * add save notification * opti uploading process * fix did not close image selector bug * check image content type when drag web link image * fix: unable to preview relative path image. * emit change event after paste/drop image * add url map in image selector * feat: screenshot and auto insert the screenshot image * update error handler * feat: use the native screencapture command line on macOs system * opti: drop image * fix: handle enter error when cursor is after a image * fix: hasOwnProperty error * remove debug codes * fix: backspace when the previous ele is image * fix: CI error and optimize some codes * use hash of file path to generate the copied filename * change default imageInsertAction to `path` * fix: typo * remove some unused codes and opti get image file name * fix some bugs and opti codes * update image edit icon * romove screen capture on Linux and Windows * fix: conflict * fix error that can not insert image after the existed image or before existed image
238 lines
6.2 KiB
JavaScript
238 lines
6.2 KiB
JavaScript
'use strict'
|
|
|
|
process.env.BABEL_ENV = 'renderer'
|
|
|
|
const path = require('path')
|
|
const webpack = require('webpack')
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
|
const SpritePlugin = require('svg-sprite-loader/plugin')
|
|
const postcssPresetEnv = require('postcss-preset-env')
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
|
|
|
|
const { getRendererEnvironmentDefinitions } = require('./marktextEnvironment')
|
|
const { dependencies } = require('../package.json')
|
|
const proMode = process.env.NODE_ENV === 'production'
|
|
/**
|
|
* List of node_modules to include in webpack bundle
|
|
* Required for specific packages like Vue UI libraries
|
|
* that provide pure *.vue files that need compiling
|
|
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
|
|
*/
|
|
const whiteListedModules = ['vue']
|
|
|
|
const rendererConfig = {
|
|
mode: 'development',
|
|
devtool: '#cheap-module-eval-source-map',
|
|
entry: {
|
|
renderer: path.join(__dirname, '../src/renderer/main.js')
|
|
},
|
|
externals: [
|
|
...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(js|vue)$/,
|
|
enforce: 'pre',
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: 'eslint-loader',
|
|
options: {
|
|
formatter: require('eslint-friendly-formatter'),
|
|
failOnError: true
|
|
}
|
|
}
|
|
},
|
|
{
|
|
test: /(theme\-chalk(?:\/|\\)index|katex|github\-markdown|prism[\-a-z]*|\.theme)\.css$/,
|
|
use: [
|
|
'to-string-loader',
|
|
'css-loader'
|
|
]
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
exclude: /(theme\-chalk(?:\/|\\)index|katex|github\-markdown|prism[\-a-z]*|\.theme)\.css$/,
|
|
use: [
|
|
proMode ? MiniCssExtractPlugin.loader : 'style-loader',
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
{ loader: 'postcss-loader', options: {
|
|
ident: 'postcss',
|
|
plugins: () => [
|
|
postcssPresetEnv({
|
|
stage: 0
|
|
})
|
|
]
|
|
} }
|
|
]
|
|
},
|
|
{
|
|
test: /\.html$/,
|
|
use: 'vue-html-loader'
|
|
},
|
|
{
|
|
test: /\.js$/,
|
|
use: 'babel-loader',
|
|
exclude: /node_modules/
|
|
},
|
|
{
|
|
test: /\.node$/,
|
|
use: 'node-loader'
|
|
},
|
|
{
|
|
test: /\.vue$/,
|
|
use: {
|
|
loader: 'vue-loader',
|
|
options: {
|
|
sourceMap: true
|
|
}
|
|
}
|
|
},
|
|
{
|
|
test: /\.svg$/,
|
|
use: [
|
|
{
|
|
loader: 'svg-sprite-loader',
|
|
options: {
|
|
extract: true,
|
|
publicPath: './static/'
|
|
}
|
|
},
|
|
'svgo-loader'
|
|
]
|
|
},
|
|
{
|
|
test: /\.(png|jpe?g|gif)(\?.*)?$/,
|
|
use: {
|
|
loader: 'url-loader',
|
|
query: {
|
|
limit: 10000,
|
|
name: 'imgs/[name]--[folder].[ext]'
|
|
}
|
|
}
|
|
},
|
|
{
|
|
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
|
|
loader: 'url-loader',
|
|
options: {
|
|
limit: 10000,
|
|
name: 'media/[name]--[folder].[ext]'
|
|
}
|
|
},
|
|
{
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
use: {
|
|
loader: 'url-loader',
|
|
query: {
|
|
limit: 100000,
|
|
name: 'fonts/[name]--[folder].[ext]'
|
|
}
|
|
}
|
|
},
|
|
{
|
|
test: /\.md$/,
|
|
use: [
|
|
'raw-loader'
|
|
]
|
|
}
|
|
]
|
|
},
|
|
node: {
|
|
__dirname: !proMode,
|
|
__filename: !proMode
|
|
},
|
|
plugins: [
|
|
new SpritePlugin(),
|
|
new HtmlWebpackPlugin({
|
|
filename: 'index.html',
|
|
template: path.resolve(__dirname, '../src/index.ejs'),
|
|
minify: {
|
|
collapseWhitespace: true,
|
|
removeAttributeQuotes: true,
|
|
removeComments: true
|
|
},
|
|
nodeModules: process.env.NODE_ENV !== 'production'
|
|
? path.resolve(__dirname, '../node_modules')
|
|
: false
|
|
}),
|
|
new webpack.NoEmitOnErrorsPlugin(),
|
|
new webpack.DefinePlugin(getRendererEnvironmentDefinitions()),
|
|
new VueLoaderPlugin()
|
|
],
|
|
output: {
|
|
filename: '[name].js',
|
|
libraryTarget: 'commonjs2',
|
|
path: path.join(__dirname, '../dist/electron')
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'main': path.join(__dirname, '../src/main'),
|
|
'@': path.join(__dirname, '../src/renderer'),
|
|
'common': path.join(__dirname, '../src/common'),
|
|
'muya': path.join(__dirname, '../src/muya'),
|
|
'vue$': 'vue/dist/vue.esm.js'
|
|
},
|
|
extensions: ['.js', '.vue', '.json', '.css', '.node']
|
|
},
|
|
target: 'electron-renderer'
|
|
}
|
|
|
|
/**
|
|
* Adjust rendererConfig for development settings
|
|
*/
|
|
if (!proMode) {
|
|
rendererConfig.plugins.push(
|
|
new webpack.DefinePlugin({
|
|
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
|
|
}),
|
|
new webpack.HotModuleReplacementPlugin()
|
|
)
|
|
}
|
|
|
|
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test' &&
|
|
!process.env.MARKTEXT_DEV_HIDE_BROWSER_ANALYZER) {
|
|
rendererConfig.plugins.push(
|
|
new BundleAnalyzerPlugin()
|
|
)
|
|
}
|
|
|
|
// Fix debugger breakpoints
|
|
if (!proMode && process.env.MARKTEXT_BUILD_VSCODE_DEBUG) {
|
|
rendererConfig.devtool = '#inline-source-map'
|
|
}
|
|
|
|
/**
|
|
* Adjust rendererConfig for production settings
|
|
*/
|
|
if (proMode) {
|
|
rendererConfig.devtool = '#nosources-source-map'
|
|
rendererConfig.mode = 'production'
|
|
rendererConfig.plugins.push(
|
|
new MiniCssExtractPlugin({
|
|
// Options similar to the same options in webpackOptions.output
|
|
// both options are optional
|
|
filename: '[name].[hash].css',
|
|
chunkFilename: '[id].[hash].css'
|
|
}),
|
|
new CopyWebpackPlugin([
|
|
{
|
|
from: path.join(__dirname, '../static'),
|
|
to: path.join(__dirname, '../dist/electron/static'),
|
|
ignore: ['.*']
|
|
},
|
|
{
|
|
from: path.resolve(__dirname, '../node_modules/codemirror/mode/*/*'),
|
|
to: path.join(__dirname, '../dist/electron/codemirror/mode/[name]/[name].js')
|
|
}
|
|
]),
|
|
new webpack.LoaderOptionsPlugin({
|
|
minimize: true
|
|
})
|
|
)
|
|
}
|
|
|
|
module.exports = rendererConfig
|