From 99c217872193a067b620895b80809c90266f3311 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 4 Jan 2019 18:27:29 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=BE=D0=B2?= =?UTF-8?q?=20webpack=20=D0=B4=D0=BB=D1=8F=20=D0=BB=D1=83=D1=87=D1=88?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/webpack.base.config.js | 10 +++++----- build/webpack.dev.config.js | 16 ++++++++++++++-- build/webpack.prod.config.js | 16 ++++++++++++++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/build/webpack.base.config.js b/build/webpack.base.config.js index bfa9574d..ecf032e9 100644 --- a/build/webpack.base.config.js +++ b/build/webpack.base.config.js @@ -2,12 +2,12 @@ const path = require("path"); const webpack = require("webpack"); const VueLoaderPlugin = require('vue-loader/lib/plugin'); +const clientDir = path.resolve(__dirname, '../client'); + module.exports = { - entry: [path.resolve(__dirname, '../client/main.js')], + entry: [`${clientDir}/main.js`], output: { - path: path.resolve(__dirname, '../server/public/app'), publicPath: '/app/', - filename: 'bundle.js' }, module: { @@ -23,7 +23,7 @@ module.exports = { 'syntax-dynamic-import', 'transform-decorators-legacy', 'transform-class-properties', - ["component", { "libraryName": "element-ui", "styleLibraryName": "~client/theme" } ] + ["component", { "libraryName": "element-ui", "styleLibraryName": `~${clientDir}/theme` } ] ] } }, @@ -61,6 +61,6 @@ module.exports = { }, plugins: [ - new VueLoaderPlugin() + new VueLoaderPlugin(), ] }; diff --git a/build/webpack.dev.config.js b/build/webpack.dev.config.js index f47d0615..ca710d5f 100644 --- a/build/webpack.dev.config.js +++ b/build/webpack.dev.config.js @@ -5,10 +5,18 @@ const merge = require("webpack-merge"); const baseWpConfig = require("./webpack.base.config"); baseWpConfig.entry.unshift("webpack-hot-middleware/client"); +const HtmlWebpackPlugin = require('html-webpack-plugin'); + +const publicDir = path.resolve(__dirname, '../server/public'); +const clientDir = path.resolve(__dirname, '../client'); module.exports = merge(baseWpConfig, { - mode: 'none', + mode: 'development', devtool: "#inline-source-map", + output: { + path: `${publicDir}/app`, + filename: 'bundle.js' + }, module: { rules: [ @@ -28,6 +36,10 @@ module.exports = merge(baseWpConfig, { plugins: [ new webpack.HotModuleReplacementPlugin(), - new webpack.NoEmitOnErrorsPlugin() + new webpack.NoEmitOnErrorsPlugin(), + new HtmlWebpackPlugin({ + template: `${clientDir}/index.html.template`, + filename: `${publicDir}/index.html` + }) ] }); diff --git a/build/webpack.prod.config.js b/build/webpack.prod.config.js index 7aefb2d0..21814ee9 100644 --- a/build/webpack.prod.config.js +++ b/build/webpack.prod.config.js @@ -7,9 +7,17 @@ const TerserPlugin = require('terser-webpack-plugin'); const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const CleanWebpackPlugin = require('clean-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); + +const publicDir = path.resolve(__dirname, '../dist/public'); +const clientDir = path.resolve(__dirname, '../client'); module.exports = merge(baseWpConfig, { mode: 'production', + output: { + path: `${publicDir}/app`, + filename: 'bundle.[contenthash].js' + }, module: { rules: [ { @@ -32,9 +40,13 @@ module.exports = merge(baseWpConfig, { ] }, plugins: [ - new CleanWebpackPlugin([`${baseWpConfig.output.path}/*.*`], {root: path.resolve(__dirname, '..')}), + new CleanWebpackPlugin([`${publicDir}`], {root: path.resolve(__dirname, '..')}), new MiniCssExtractPlugin({ - filename: "[name].css" + filename: "[name].[contenthash].css" + }), + new HtmlWebpackPlugin({ + template: `${clientDir}/index.html.template`, + filename: `${publicDir}/index.html` }) ] });