From 56f67f05385543281b92f48f826cc67fc817f2bd Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 31 Jan 2018 15:33:34 +0800 Subject: [PATCH] perf[chore]: webpack --- build/webpack.base.conf.js | 8 -------- build/webpack.dev.conf.js | 18 ++++++++++++++++-- build/webpack.prod.conf.js | 8 ++++++++ src/components/Tinymce/index.vue | 2 ++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index f2878ac2..97bc6e2b 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -3,7 +3,6 @@ const path = require('path') const utils = require('./utils') const config = require('../config') const vueLoaderConfig = require('./vue-loader.conf') -const CopyWebpackPlugin = require('copy-webpack-plugin') function resolve (dir) { return path.join(__dirname, '..', dir) @@ -87,13 +86,6 @@ module.exports = { } ] }, - plugins:[ - new CopyWebpackPlugin([ - { - from: 'static/tinymce' - } - ]) - ], node: { // prevent webpack from injecting useless setImmediate polyfill because Vue // source contains it (although only uses it if it's native). diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js index 212d0815..c8ec02f3 100644 --- a/build/webpack.dev.conf.js +++ b/build/webpack.dev.conf.js @@ -1,10 +1,11 @@ 'use strict' -const path = require('path') const utils = require('./utils') const webpack = require('webpack') const config = require('../config') const merge = require('webpack-merge') +const path = require('path') const baseWebpackConfig = require('./webpack.base.conf') +const CopyWebpackPlugin = require('copy-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') const portfinder = require('portfinder') @@ -26,8 +27,13 @@ const devWebpackConfig = merge(baseWebpackConfig, { // these devServer options should be customized in /config/index.js devServer: { clientLogLevel: 'warning', - historyApiFallback: true, + historyApiFallback: { + rewrites: [ + { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, + ], + }, hot: true, + contentBase: false, // since we use CopyWebpackPlugin. compress: true, host: HOST || config.dev.host, port: PORT || config.dev.port, @@ -57,6 +63,14 @@ const devWebpackConfig = merge(baseWebpackConfig, { favicon: resolve('favicon.ico'), title: 'vue-element-admin' }), + // copy custom static assets + new CopyWebpackPlugin([ + { + from: path.resolve(__dirname, '../static'), + to: config.dev.assetsSubDirectory, + ignore: ['.*'] + } + ]) ] }) diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index cd75e5ad..d8f155c4 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -127,6 +127,14 @@ const webpackConfig = merge(baseWebpackConfig, { var context = module.context; return context && (context.indexOf('xlsx') >= 0); } + }), + // split tinymce into its own file + new webpack.optimize.CommonsChunkPlugin({ + async: 'tinymce', + minChunks(module) { + var context = module.context; + return context && (context.indexOf('tinymce') >= 0); + } }), // split codemirror into its own file new webpack.optimize.CommonsChunkPlugin({ diff --git a/src/components/Tinymce/index.vue b/src/components/Tinymce/index.vue index c12913c5..5376cf5b 100644 --- a/src/components/Tinymce/index.vue +++ b/src/components/Tinymce/index.vue @@ -11,6 +11,8 @@ // Import Tinymce import tinymce from 'tinymce/tinymce' +tinymce.baseURL = 'static/tinymce' + // A theme is also required import 'tinymce/themes/modern/theme'