pull/429/head
hunterlong 2020-02-21 11:38:21 -08:00
parent 7d0501823d
commit cb7787f26c
4 changed files with 24 additions and 15 deletions

View File

@ -7,6 +7,7 @@ const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin'); const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin'); const CompressionPlugin = require('compression-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const helpers = require('./helpers'); const helpers = require('./helpers');
const commonConfig = require('./webpack.config.common'); const commonConfig = require('./webpack.config.common');
const isProd = process.env.NODE_ENV === 'production'; const isProd = process.env.NODE_ENV === 'production';
@ -17,12 +18,13 @@ const webpackConfig = merge(commonConfig, {
mode: 'production', mode: 'production',
output: { output: {
path: helpers.root('dist'), path: helpers.root('dist'),
publicPath: '/', publicPath: '',
filename: `js/[name].js`, filename: 'js/bundle.js',
chunkFilename: 'js/[name].js' chunkFilename: 'js/[name].chunk.js',
}, },
optimization: { optimization: {
runtimeChunk: 'single', runtimeChunk: 'single',
minimize: true,
minimizer: [ minimizer: [
new OptimizeCSSAssetsPlugin({ new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: { cssProcessorPluginOptions: {
@ -42,10 +44,9 @@ const webpackConfig = merge(commonConfig, {
cacheGroups: { cacheGroups: {
vendor: { vendor: {
test: /[\\/]node_modules[\\/]/, test: /[\\/]node_modules[\\/]/,
name (module) { chunks: "all",
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; name: "vendor",
return `${packageName.replace('@', '')}`; enforce: true
}
}, },
styles: { styles: {
test: /\.css$/, test: /\.css$/,
@ -58,6 +59,7 @@ const webpackConfig = merge(commonConfig, {
}, },
plugins: [ plugins: [
new webpack.EnvironmentPlugin(environment), new webpack.EnvironmentPlugin(environment),
new CleanWebpackPlugin(),
new MiniCSSExtractPlugin({ new MiniCSSExtractPlugin({
filename: 'css/[name].css', filename: 'css/[name].css',
chunkFilename: 'css/[name].css' chunkFilename: 'css/[name].css'

View File

@ -45,6 +45,7 @@
"@vue/test-utils": "^1.0.0-beta.31", "@vue/test-utils": "^1.0.0-beta.31",
"babel-eslint": "~10.0", "babel-eslint": "~10.0",
"babel-loader": "~8.0", "babel-loader": "~8.0",
"clean-webpack-plugin": "^3.0.0",
"compression-webpack-plugin": "~2.0", "compression-webpack-plugin": "~2.0",
"cross-env": "~5.2", "cross-env": "~5.2",
"css-loader": "~2.1", "css-loader": "~2.1",

View File

@ -16,9 +16,9 @@
{{else}} {{else}}
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
{{if USING_ASSETS}} {{if USING_ASSETS}}
<link rel="stylesheet" href="css/bootstrap.min.css"> <link href="css/vendor.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link rel="stylesheet" href="css/base.css"> <link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="font/all.css">
{{else}} {{else}}
<% _.each(htmlWebpackPlugin.tags.headTags, function(headTag) { %> <% _.each(htmlWebpackPlugin.tags.headTags, function(headTag) { %>
<%= headTag %> <% }) %> <%= headTag %> <% }) %>
@ -33,7 +33,11 @@
<div id="app"></div> <div id="app"></div>
{{if USE_CDN}} {{if USE_CDN}}
<script src="https://assets.statping.com/js/bundle.js"></script>
<script src="https://assets.statping.com/js/vendor.chunk.js"></script>
<script src="https://assets.statping.com/js/polyfill.chunk.js"></script>
<script src="https://assets.statping.com/js/style.chunk.js"></script>
<script src="https://assets.statping.com/js/main.chunk.js"></script>
{{else}} {{else}}
<% _.each(htmlWebpackPlugin.tags.bodyTags, function(bodyTag) { %> <% _.each(htmlWebpackPlugin.tags.bodyTags, function(bodyTag) { %>
<%= bodyTag %> <% }) %> <%= bodyTag %> <% }) %>

View File

@ -61,7 +61,7 @@ func Router() *mux.Router {
r.PathPrefix("/css/").Handler(Gzip(staticAssets("css"))) r.PathPrefix("/css/").Handler(Gzip(staticAssets("css")))
r.PathPrefix("/font/").Handler(staticAssets("font")) r.PathPrefix("/font/").Handler(staticAssets("font"))
r.PathPrefix("/js/").Handler(Gzip(staticAssets("css"))) r.PathPrefix("/js/").Handler(Gzip(staticAssets("js")))
r.PathPrefix("/robots.txt").Handler(http.StripPrefix(basePath, indexHandler)) r.PathPrefix("/robots.txt").Handler(http.StripPrefix(basePath, indexHandler))
r.PathPrefix("/favicon.ico").Handler(http.StripPrefix(basePath, indexHandler)) r.PathPrefix("/favicon.ico").Handler(http.StripPrefix(basePath, indexHandler))
r.PathPrefix("/banner.png").Handler(http.StripPrefix(basePath, indexHandler)) r.PathPrefix("/banner.png").Handler(http.StripPrefix(basePath, indexHandler))
@ -119,16 +119,18 @@ func Router() *mux.Router {
api.Handle("/api/services/{id}", scoped(apiServiceHandler)).Methods("GET") api.Handle("/api/services/{id}", scoped(apiServiceHandler)).Methods("GET")
api.Handle("/api/reorder/services", authenticated(reorderServiceHandler, false)).Methods("POST") api.Handle("/api/reorder/services", authenticated(reorderServiceHandler, false)).Methods("POST")
api.Handle("/api/services/{id}/running", authenticated(apiServiceRunningHandler, false)).Methods("POST") api.Handle("/api/services/{id}/running", authenticated(apiServiceRunningHandler, false)).Methods("POST")
api.Handle("/api/services/{id}/data", cached("30s", "application/json", apiServiceDataHandler)).Methods("GET")
api.Handle("/api/services/{id}/failure_data", cached("30s", "application/json", apiServiceFailureDataHandler)).Methods("GET")
api.Handle("/api/services/{id}/ping", cached("30s", "application/json", apiServicePingDataHandler)).Methods("GET")
api.Handle("/api/services/{id}/heatmap", cached("30s", "application/json", apiServiceHeatmapHandler)).Methods("GET")
api.Handle("/api/services/{id}", authenticated(apiServiceUpdateHandler, false)).Methods("POST") api.Handle("/api/services/{id}", authenticated(apiServiceUpdateHandler, false)).Methods("POST")
api.Handle("/api/services/{id}", authenticated(apiServiceDeleteHandler, false)).Methods("DELETE") api.Handle("/api/services/{id}", authenticated(apiServiceDeleteHandler, false)).Methods("DELETE")
api.Handle("/api/services/{id}/failures", scoped(apiServiceFailuresHandler)).Methods("GET") api.Handle("/api/services/{id}/failures", scoped(apiServiceFailuresHandler)).Methods("GET")
api.Handle("/api/services/{id}/failures", authenticated(servicesDeleteFailuresHandler, false)).Methods("DELETE") api.Handle("/api/services/{id}/failures", authenticated(servicesDeleteFailuresHandler, false)).Methods("DELETE")
api.Handle("/api/services/{id}/hits", scoped(apiServiceHitsHandler)).Methods("GET") api.Handle("/api/services/{id}/hits", scoped(apiServiceHitsHandler)).Methods("GET")
// API SERVICE CHART DATA Routes
api.Handle("/api/services/{id}/data", cached("30s", "application/json", apiServiceDataHandler)).Methods("GET")
api.Handle("/api/services/{id}/failure_data", cached("30s", "application/json", apiServiceFailureDataHandler)).Methods("GET")
api.Handle("/api/services/{id}/ping", cached("30s", "application/json", apiServicePingDataHandler)).Methods("GET")
api.Handle("/api/services/{id}/heatmap", cached("30s", "application/json", apiServiceHeatmapHandler)).Methods("GET")
// API INCIDENTS Routes // API INCIDENTS Routes
api.Handle("/api/incidents", readOnly(apiAllIncidentsHandler, false)).Methods("GET") api.Handle("/api/incidents", readOnly(apiAllIncidentsHandler, false)).Methods("GET")
api.Handle("/api/incidents", authenticated(apiCreateIncidentHandler, false)).Methods("POST") api.Handle("/api/incidents", authenticated(apiCreateIncidentHandler, false)).Methods("POST")