Browse Source

webpack5

master
陈裕财 4 years ago
parent
commit
f16f60d00c
  1. 53
      build/webpack.base.conf.js
  2. 7
      build/webpack.prod.conf.js
  3. 4
      src/components/Image/UploadImage.vue
  4. 72
      src/components/Tinymce/index.vue

53
build/webpack.base.conf.js

@ -54,8 +54,8 @@ var threadLoaderConfig={
// 可以修改名称来创建其余选项都一样的池(pool) // 可以修改名称来创建其余选项都一样的池(pool)
name: "my-pool" name: "my-pool"
} }
}
const publicCssLoaders=process.env.NODE_ENV === 'production'?[{loader:MiniCssExtractPlugin.loader,options:{publicPath:'../'}},'css-loader']:[ 'style-loader','css-loader']
}
const publicCssLoaders=process.env.NODE_ENV === 'production'?[{loader:MiniCssExtractPlugin.loader,options:{publicPath:'../'}},'css-loader','postcss-loader']:[ 'style-loader','css-loader','postcss-loader']
function resolve(dir) { function resolve(dir) {
return path.join(__dirname, '..', dir) return path.join(__dirname, '..', dir)
@ -79,7 +79,7 @@ module.exports = {
}, },
output: { output: {
clean:true, clean:true,
path: config.build.assetsRoot,
path: config.build.assetsRoot,
filename: 'js/[name].[contenthash].js', filename: 'js/[name].[contenthash].js',
pathinfo: false, pathinfo: false,
publicPath: process.env.NODE_ENV === 'production' publicPath: process.env.NODE_ENV === 'production'
@ -96,16 +96,15 @@ module.exports = {
// 加载器 // 加载器
module: { module: {
// https://doc.webpack-china.org/guides/migrating/#module-loaders-module-rules // https://doc.webpack-china.org/guides/migrating/#module-loaders-module-rules
rules: [
rules: [
//...(config.dev.useEslint ? [createLintingRule()] : []), //...(config.dev.useEslint ? [createLintingRule()] : []),
{ {
test: /\.vue$/, test: /\.vue$/,
//include: resolve('src'),
use:[ use:[
threadLoaderConfig, threadLoaderConfig,
{ {
loader: 'vue-loader', loader: 'vue-loader',
/**
/**
options:vueLoaderConfig, options:vueLoaderConfig,
*/ */
options: { options: {
@ -115,30 +114,30 @@ module.exports = {
{ loader: 'cache-loader' }, { loader: 'cache-loader' },
{ loader: 'babel-loader', options: { presets: ['env'] } } { loader: 'babel-loader', options: { presets: ['env'] } }
] ]
},
},
extractCSS: true, extractCSS: true,
hotReload:true,
},
hotReload:true,
},
} }
] ]
},
},
{ {
test: /\.css$/, test: /\.css$/,
use: publicCssLoaders, use: publicCssLoaders,
},
},
{ {
test: /\.(sa|sc)ss$/, test: /\.(sa|sc)ss$/,
use: publicCssLoaders.concat([
use: publicCssLoaders.concat([
// 将 Sass 编译成 CSS // 将 Sass 编译成 CSS
'sass-loader', 'sass-loader',
]), ]),
},
},
{ {
test: /\.less$/, test: /\.less$/,
use: publicCssLoaders.concat([
use: publicCssLoaders.concat([
// 将 Sass 编译成 CSS // 将 Sass 编译成 CSS
'less-loader', 'less-loader',
]), ]),
@ -149,7 +148,7 @@ module.exports = {
// 将 Sass 编译成 CSS // 将 Sass 编译成 CSS
'stylus-loader', 'stylus-loader',
]), ]),
},
},
{ // 配置Babel将ES6+ 转换为ES5 { // 配置Babel将ES6+ 转换为ES5
test: /\.js$/, test: /\.js$/,
use:[ use:[
@ -159,10 +158,10 @@ module.exports = {
options: { options: {
presets: ['env'], presets: ['env'],
plugins: ['transform-runtime'] plugins: ['transform-runtime']
},
},
}, },
], ],
include: resolve('src'),
include: resolve('src'),
}, },
{ {
test: /\.svg$/, test: /\.svg$/,
@ -181,7 +180,7 @@ module.exports = {
} }
}, },
{ {
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
type: 'asset/resource', type: 'asset/resource',
generator: { generator: {
filename: 'media/[hash][ext][query]' filename: 'media/[hash][ext][query]'
@ -196,27 +195,23 @@ module.exports = {
} }
] ]
},
},
plugins: [ plugins: [
new VueLoaderPlugin(), new VueLoaderPlugin(),
], ],
optimization: { optimization: {
splitChunks: { splitChunks: {
chunks: 'all',
minSize: 200000,
enforceSizeThreshold: 400000,
chunks: 'all',
cacheGroups: { cacheGroups: {
defaultVendors: { defaultVendors: {
test: /[\\/]node_modules[\\/]/, test: /[\\/]node_modules[\\/]/,
priority: -10, priority: -10,
reuseExistingChunk: true,
enforceSizeThreshold: 400000,
reuseExistingChunk: true,
}, },
default: { default: {
minChunks: 2, minChunks: 2,
priority: -20, priority: -20,
reuseExistingChunk: true,
enforceSizeThreshold: 400000,
reuseExistingChunk: true,
}, },
}, },
}, },

7
build/webpack.prod.conf.js

@ -68,7 +68,6 @@ const webpackConfig = merge(baseWebpackConfig, {
}), }),
], ],
optimization: { optimization: {
moduleIds:'hashed',
minimize: true, minimize: true,
minimizer:[ minimizer:[
new CssMinimizerPlugin({ new CssMinimizerPlugin({
@ -83,11 +82,7 @@ const webpackConfig = merge(baseWebpackConfig, {
}) })
], ],
splitChunks: { splitChunks: {
chunks: 'all',
minSize: {
javascript: 80000,
webassembly: 80000,
},
chunks: 'all'
}, },
}, },
}) })

4
src/components/Image/UploadImage.vue

@ -250,7 +250,8 @@
pageSize: this.pageInfo.pageSize, pageSize: this.pageInfo.pageSize,
pageNum: this.pageInfo.pageNum, pageNum: this.pageInfo.pageNum,
total: this.pageInfo.total total: this.pageInfo.total
};
};
if(this.pageInfo.orderFields!=null && this.pageInfo.orderFields.length>0){ if(this.pageInfo.orderFields!=null && this.pageInfo.orderFields.length>0){
let orderBys=[]; let orderBys=[];
for(var i=0;i<this.pageInfo.orderFields.length;i++){ for(var i=0;i<this.pageInfo.orderFields.length;i++){
@ -273,6 +274,7 @@
return; return;
} }
params.branchId = this.branchId; params.branchId = this.branchId;
this.selectImages=[];
this.listLoading = true; this.listLoading = true;
listImage(params).then((res) => { listImage(params).then((res) => {
var tips=res.data.tips; var tips=res.data.tips;

72
src/components/Tinymce/index.vue

@ -1,22 +1,25 @@
<template> <template>
<div :class="{fullscreen:fullscreen}" class="tinymce-container editor-container"> <div :class="{fullscreen:fullscreen}" class="tinymce-container editor-container">
<textarea :id="tinymceId" class="tinymce-textarea" />
<textarea :id="tinymceId" class="tinymce-textarea" />
<el-dialog id="editor-dialog" class="image-dialog" title="选择图片" :visible.sync="dialogVisible" width="70%" :close-on-click-modal="false" append-to-body> <el-dialog id="editor-dialog" class="image-dialog" title="选择图片" :visible.sync="dialogVisible" width="70%" :close-on-click-modal="false" append-to-body>
<upload-image :multiple="true" :branch-id="userInfo.branchId" :dept-id="userInfo.deptid" :visible="dialogVisible" @cancel="dialogVisible=false" @confirm="handleConfirm"></upload-image> <upload-image :multiple="true" :branch-id="userInfo.branchId" :dept-id="userInfo.deptid" :visible="dialogVisible" @cancel="dialogVisible=false" @confirm="handleConfirm"></upload-image>
</el-dialog>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import config from '@/common/config';//import
import UploadImage from '@/components/Image/UploadImage';
import { mapGetters } from 'vuex'
import config from '@/common/config';//import
import UploadImage from '@/components/Image/UploadImage';
import { mapGetters } from 'vuex'
import plugins from './plugins' import plugins from './plugins'
import toolbar from './toolbar'
import toolbar from './toolbar'
export default {
export default {
name: 'Tinymce', name: 'Tinymce',
components: { UploadImage }, components: { UploadImage },
props: {
props: {
value: { value: {
type: String, type: String,
default: '' default: ''
@ -39,10 +42,10 @@ export default {
} }
}, },
data() { data() {
return {
return {
imageList:[], imageList:[],
dialogVisible:false, dialogVisible:false,
editorHtmlData:this.value,
editorHtmlData:this.value,
tinymceId: 'vue-tinymce-'+new Date().getTime() + ((Math.random() * 1000).toFixed(0) + ''), tinymceId: 'vue-tinymce-'+new Date().getTime() + ((Math.random() * 1000).toFixed(0) + ''),
fullscreen: false, fullscreen: false,
languageTypeList: { languageTypeList: {
@ -54,19 +57,19 @@ export default {
computed: { computed: {
language() { language() {
return this.languageTypeList[this.$store.getters.language] return this.languageTypeList[this.$store.getters.language]
},
},
...mapGetters([ ...mapGetters([
'userInfo' 'userInfo'
]) ])
}, },
watch: { watch: {
value(val) {
value(val) {
if(val==this.editorHtmlData){ if(val==this.editorHtmlData){
return; return;
} }
this.$nextTick(() => window.tinymce.get(this.tinymceId).setContent(val || ''))
this.$nextTick(() => window.tinymce.get(this.tinymceId).setContent(val || ''))
}, },
editorHtmlData(val) {
editorHtmlData(val) {
this.$emit("input",val) this.$emit("input",val)
}, },
language() { language() {
@ -75,12 +78,12 @@ export default {
} }
}, },
mounted() { mounted() {
this.$nextTick(() => this.initTinymce())
this.$nextTick(() => this.initTinymce())
}, },
/** /**
activated() { activated() {
this.initTinymce() this.initTinymce()
}, },
deactivated() { deactivated() {
this.destroyTinymce() this.destroyTinymce()
@ -111,32 +114,33 @@ export default {
imagetools_cors_hosts: ['www.qingqinkj.com', 'codepen.io'], imagetools_cors_hosts: ['www.qingqinkj.com', 'codepen.io'],
default_link_target: '_blank', default_link_target: '_blank',
link_title: false, link_title: false,
convert_urls:false,
fontsize_formats: "8pt 10pt 12pt 14pt 18pt 20pt 24pt 28pt 30pt 36pt 38pt 40pt 42pt 46pt 48pt", fontsize_formats: "8pt 10pt 12pt 14pt 18pt 20pt 24pt 28pt 30pt 36pt 38pt 40pt 42pt 46pt 48pt",
font_formats: "微软雅黑='微软雅黑';宋体='宋体';黑体='黑体';仿宋='仿宋';楷体='楷体';隶书='隶书';幼圆='幼圆';Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings", font_formats: "微软雅黑='微软雅黑';宋体='宋体';黑体='黑体';仿宋='仿宋';楷体='楷体';隶书='隶书';幼圆='幼圆';Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings",
nonbreaking_force_tab: true, // inserting nonbreaking space &nbsp; need Nonbreaking Space Plugin nonbreaking_force_tab: true, // inserting nonbreaking space &nbsp; need Nonbreaking Space Plugin
init_instance_callback: editor => {
init_instance_callback: editor => {
if (_this.value) { if (_this.value) {
editor.setContent(_this.value) editor.setContent(_this.value)
}
editor.on('NodeChange Change KeyUp SetContent', () => {
_this.editorHtmlData=editor.getContent()
}
editor.on('NodeChange Change KeyUp SetContent', () => {
_this.editorHtmlData=editor.getContent()
}) })
}, },
setup(editor) { setup(editor) {
editor.on('FullscreenStateChanged', (e) => { editor.on('FullscreenStateChanged', (e) => {
_this.fullscreen = e.state _this.fullscreen = e.state
}) })
editor.addButton('imageList',{ editor.addButton('imageList',{
text:'图片库', text:'图片库',
icon:false, icon:false,
onclick:function(){ onclick:function(){
_this.dialogVisible=true;
_this.$nextTick(()=>{
_this.dialogVisible=true;
_this.$nextTick(()=>{
//document.getElementById("editor-dialog").style.zIndex="100000" //document.getElementById("editor-dialog").style.zIndex="100000"
})
})
} }
}) })
} }
@ -173,9 +177,9 @@ export default {
// console.log(err); // console.log(err);
// }); // });
// }, // },
})
})
this.setContent(this.value) this.setContent(this.value)
}, },
destroyTinymce() { destroyTinymce() {
const tinymce = window.tinymce.get(this.tinymceId) const tinymce = window.tinymce.get(this.tinymceId)
@ -186,13 +190,13 @@ export default {
tinymce.destroy() tinymce.destroy()
} }
}, },
setContent(value) {
setContent(value) {
window.tinymce.get(this.tinymceId).setContent(value) window.tinymce.get(this.tinymceId).setContent(value)
}, },
getContent() { getContent() {
window.tinymce.get(this.tinymceId).getContent() window.tinymce.get(this.tinymceId).getContent()
}, },
insertImage () {
insertImage () {
let imageList = this.imageList; let imageList = this.imageList;
let imageHtml = ""; let imageHtml = "";
(imageList || []).map(item => { (imageList || []).map(item => {
@ -203,10 +207,10 @@ export default {
} }
this.dialogVisible = false; this.dialogVisible = false;
}, },
handleConfirm(imgs){
handleConfirm(imgs){
this.imageList=imgs//{url:xxx,remark:xxxx} this.imageList=imgs//{url:xxx,remark:xxxx}
this.insertImage();
this.insertImage();
}, },
imageSuccessCBK(arr) { imageSuccessCBK(arr) {
const _this = this const _this = this
@ -247,4 +251,4 @@ export default {
z-index:20000 !important; z-index:20000 !important;
} }
</style>
</style>
Loading…
Cancel
Save