瀏覽代碼

htaccess for routing #2054

bach 2 年之前
父節點
當前提交
7dbb43e0ed
共有 3 個文件被更改,包括 32 次插入6 次删除
  1. 7 5
      build/webpack.config.base.js
  2. 14 1
      build/webpack.config.prod.js
  3. 11 0
      static/.htaccess

+ 7 - 5
build/webpack.config.base.js

@@ -74,10 +74,12 @@ module.exports = {
     }),
     }),
     new HtmlWebpackHarddiskPlugin(),
     new HtmlWebpackHarddiskPlugin(),
     new VueLoaderPlugin(),
     new VueLoaderPlugin(),
-    new CopyWebpackPlugin([{
-      from: utils.resolve('static/img'),
-      to: utils.resolve('dist/static/img'),
-      toType: 'dir'
-    }])
+    new CopyWebpackPlugin([
+      {
+        from: utils.resolve('static/img'),
+        to: utils.resolve('dist/static/img'),
+        toType: 'dir'
+      }
+    ])
   ]
   ]
 }
 }

+ 14 - 1
build/webpack.config.prod.js

@@ -1,16 +1,24 @@
 'use strict'
 'use strict'
 
 
 const webpack = require('webpack')
 const webpack = require('webpack')
+const CopyWebpackPlugin = require('copy-webpack-plugin')
 const merge = require('webpack-merge')
 const merge = require('webpack-merge')
 const baseConfig = require('./webpack.config.base')
 const baseConfig = require('./webpack.config.base')
 const MiniCssExtractPlugin  = require('mini-css-extract-plugin')
 const MiniCssExtractPlugin  = require('mini-css-extract-plugin')
 
 
+const utils = require('./utils')
+
 const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
 const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
 // ERROR in vendor.js from UglifyJs
 // ERROR in vendor.js from UglifyJs
 // RangeError: Maximum call stack size exceeded
 // RangeError: Maximum call stack size exceeded
 
 
 module.exports = merge(baseConfig, {
 module.exports = merge(baseConfig, {
   mode: 'production',
   mode: 'production',
+  // resolve: {
+  //   alias: {
+  //     'static': utils.resolve('static')
+  //   }
+  // },
   output: {
   output: {
     publicPath: '/'
     publicPath: '/'
   },
   },
@@ -66,6 +74,11 @@ module.exports = merge(baseConfig, {
     }),
     }),
     new webpack.DefinePlugin({
     new webpack.DefinePlugin({
       "process.env": "'prod'"
       "process.env": "'prod'"
-    })
+    }),
+    new CopyWebpackPlugin([{
+      from: utils.resolve('static/.htaccess'),
+      to: utils.resolve('dist/.htaccess'),
+      toType: 'file'
+    }])
   ]
   ]
 })
 })

+ 11 - 0
static/.htaccess

@@ -0,0 +1,11 @@
+<IfModule mod_negotiation.c>
+  Options -MultiViews
+</IfModule>
+<IfModule mod_rewrite.c>
+  RewriteEngine On
+  RewriteBase /
+  RewriteRule ^index\.html$ - [L]
+  RewriteCond %{REQUEST_FILENAME} !-f
+  RewriteCond %{REQUEST_FILENAME} !-d
+  RewriteRule . /index.html [L]
+</IfModule>