mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-10-29 01:30:32 +00:00
Updated webpack config for prod builds.
This commit is contained in:
2
config/env/dev.env.js
vendored
2
config/env/dev.env.js
vendored
@@ -1,3 +1,3 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
NODE_ENV: "development"
|
NODE_ENV: 'development'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
const path = require("path");
|
const path = require('path');
|
||||||
|
|
||||||
const _root = path.resolve(__dirname, "..");
|
const _root = path.resolve(__dirname, '..');
|
||||||
|
|
||||||
exports.root = function(args) {
|
exports.root = function(args) {
|
||||||
args = Array.prototype.slice.call(arguments, 0);
|
args = Array.prototype.slice.call(arguments, 0);
|
||||||
@@ -11,5 +11,5 @@ exports.root = function(args) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.assetsPath = function(_path) {
|
exports.assetsPath = function(_path) {
|
||||||
return path.posix.join("static", _path);
|
return path.posix.join('static', _path);
|
||||||
};
|
};
|
||||||
|
|||||||
28
config/planetposen.config.js
Normal file
28
config/planetposen.config.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
|
const helpers = require("./helpers");
|
||||||
|
|
||||||
|
const VinlottisConfig = {
|
||||||
|
entry: {
|
||||||
|
planetposen: ["@babel/polyfill", helpers.root("frontend", "main")]
|
||||||
|
},
|
||||||
|
optimization: {
|
||||||
|
minimizer: [
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
chunks: ["planetposen"],
|
||||||
|
filename: "../index.html",
|
||||||
|
template: "./frontend/index.html",
|
||||||
|
inject: true,
|
||||||
|
minify: {
|
||||||
|
removeComments: true,
|
||||||
|
collapseWhitespace: false,
|
||||||
|
preserveLineBreaks: true,
|
||||||
|
removeAttributeQuotes: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = VinlottisConfig;
|
||||||
@@ -2,18 +2,17 @@
|
|||||||
|
|
||||||
const VueLoaderPlugin = require("vue-loader/lib/plugin");
|
const VueLoaderPlugin = require("vue-loader/lib/plugin");
|
||||||
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
|
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
|
||||||
|
const HtmlPlugin = require("html-webpack-plugin");
|
||||||
const helpers = require("./helpers");
|
const helpers = require("./helpers");
|
||||||
const isDev = process.env.NODE_ENV === "development";
|
|
||||||
|
// const {GenerateSW} = require('workbox-webpack-plugin');
|
||||||
|
|
||||||
const webpackConfig = function(isDev) {
|
const webpackConfig = function(isDev) {
|
||||||
return {
|
return {
|
||||||
entry: {
|
|
||||||
main: ["@babel/polyfill", helpers.root("frontend", "main")]
|
|
||||||
},
|
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".js", ".vue"],
|
extensions: [".js", ".vue"],
|
||||||
alias: {
|
alias: {
|
||||||
vue$: isDev ? "vue/dist/vue.runtime.js" : "vue/dist/vue.runtime.min.js",
|
vue$: isDev ? "vue/dist/vue.min.js" : "vue/dist/vue.min.js",
|
||||||
"@": helpers.root("frontend")
|
"@": helpers.root("frontend")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -21,13 +20,22 @@ const webpackConfig = function(isDev) {
|
|||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.vue$/,
|
test: /\.vue$/,
|
||||||
loader: "vue-loader",
|
use: [
|
||||||
include: [helpers.root("frontend")]
|
{
|
||||||
|
loader: "vue-loader",
|
||||||
|
options: {
|
||||||
|
loaders: {
|
||||||
|
scss: "vue-style-loader!css-loader!sass-loader",
|
||||||
|
sass: "vue-style-loader!css-loader!sass-loader?indentedSyntax"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
loader: "babel-loader",
|
loader: "babel-loader",
|
||||||
include: [helpers.root("frontend")]
|
include: [helpers.root("src")]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
@@ -52,41 +60,29 @@ const webpackConfig = function(isDev) {
|
|||||||
{ loader: "sass-loader", options: { sourceMap: isDev } }
|
{ loader: "sass-loader", options: { sourceMap: isDev } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// test: /\.s(c|a)ss$/,
|
|
||||||
// use: [
|
|
||||||
// 'vue-style-loader',
|
|
||||||
// 'css-loader',
|
|
||||||
// {
|
|
||||||
// loader: 'sass-loader',
|
|
||||||
// // Requires sass-loader@^7.0.0
|
|
||||||
// options: {
|
|
||||||
// implementation: require('sass'),
|
|
||||||
// fiber: require('fibers'),
|
|
||||||
// indentedSyntax: true // optional
|
|
||||||
// },
|
|
||||||
// // Requires sass-loader@^8.0.0
|
|
||||||
// options: {
|
|
||||||
// implementation: require('sass'),
|
|
||||||
// sassOptions: {
|
|
||||||
// fiber: require('fibers'),
|
|
||||||
// indentedSyntax: true // optional
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
test: /\.woff(2)?(\?[a-z0-9]+)?$/,
|
test: /\.woff(2)?(\?[a-z0-9]+)?$/,
|
||||||
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
|
loader: "url-loader?limit=10000&mimetype=application/font-woff"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(ttf|eot|svg)(\?[a-z0-9]+)?$/,
|
test: /\.(ttf|eot|svg)(\?[a-z0-9]+)?$/,
|
||||||
loader: 'file-loader'
|
loader: "file-loader"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
plugins: [new VueLoaderPlugin()]
|
plugins: [
|
||||||
|
new VueLoaderPlugin(),
|
||||||
|
// new GenerateSW({
|
||||||
|
// swSrc: "./public/service-worker.js",
|
||||||
|
// swDest: './sw.js',
|
||||||
|
// clientsClaim: true,
|
||||||
|
// skipWaiting: true,
|
||||||
|
// runtimeCaching: [{
|
||||||
|
// urlPattern: new RegExp('https://www.google-analytics.com/analytics.js'),
|
||||||
|
// handler: 'StaleWhileRevalidate'
|
||||||
|
// }]
|
||||||
|
// })
|
||||||
|
]
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const helpers = require("./helpers");
|
|||||||
const commonConfig = require("./webpack.config.common");
|
const commonConfig = require("./webpack.config.common");
|
||||||
const environment = require("./env/dev.env");
|
const environment = require("./env/dev.env");
|
||||||
|
|
||||||
const webpackConfig = merge(commonConfig(true), {
|
let webpackConfig = merge(commonConfig(true), {
|
||||||
mode: "development",
|
mode: "development",
|
||||||
devtool: "cheap-module-eval-source-map",
|
devtool: "cheap-module-eval-source-map",
|
||||||
output: {
|
output: {
|
||||||
@@ -26,19 +26,29 @@ const webpackConfig = merge(commonConfig(true), {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new webpack.EnvironmentPlugin(environment),
|
new webpack.EnvironmentPlugin(environment),
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
new FriendlyErrorsPlugin(),
|
new FriendlyErrorsPlugin()
|
||||||
new HtmlPlugin({ template: "frontend/index.html", chunksSortMode: "dependency" })
|
|
||||||
],
|
],
|
||||||
devServer: {
|
devServer: {
|
||||||
compress: true,
|
compress: true,
|
||||||
historyApiFallback: true,
|
historyApiFallback: true,
|
||||||
hot: true,
|
hot: true,
|
||||||
overlay: true,
|
overlay: true,
|
||||||
port: 8080,
|
|
||||||
stats: {
|
stats: {
|
||||||
normal: true
|
normal: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
webpackConfig = merge(webpackConfig, {
|
||||||
|
entry: {
|
||||||
|
main: ["@babel/polyfill", helpers.root("src", "vinlottis-init")]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new HtmlPlugin({
|
||||||
|
template: "src/templates/Index.html",
|
||||||
|
chunksSortMode: "dependency"
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = webpackConfig;
|
module.exports = webpackConfig;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||||
const webpack = require("webpack");
|
const webpack = require("webpack");
|
||||||
const merge = require("webpack-merge");
|
const merge = require("webpack-merge");
|
||||||
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
|
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 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";
|
||||||
@@ -16,11 +16,22 @@ const environment = isProd
|
|||||||
const webpackConfig = merge(commonConfig(false), {
|
const webpackConfig = merge(commonConfig(false), {
|
||||||
mode: "production",
|
mode: "production",
|
||||||
output: {
|
output: {
|
||||||
path: helpers.root("dist"),
|
path: helpers.root("public/dist"),
|
||||||
publicPath: "/",
|
publicPath: "/dist/",
|
||||||
filename: "js/[name].bundle.js"
|
filename: "js/[name].bundle.[hash:7].js"
|
||||||
|
//filename: 'js/[name].bundle.js'
|
||||||
},
|
},
|
||||||
optimization: {
|
optimization: {
|
||||||
|
splitChunks: {
|
||||||
|
cacheGroups: {
|
||||||
|
styles: {
|
||||||
|
name: "styles",
|
||||||
|
test: /\.css$/,
|
||||||
|
chunks: "all",
|
||||||
|
enforce: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
minimizer: [
|
minimizer: [
|
||||||
new OptimizeCSSAssetsPlugin({
|
new OptimizeCSSAssetsPlugin({
|
||||||
cssProcessorPluginOptions: {
|
cssProcessorPluginOptions: {
|
||||||
@@ -35,9 +46,10 @@ const webpackConfig = merge(commonConfig(false), {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
new CleanWebpackPlugin(),
|
||||||
new webpack.EnvironmentPlugin(environment),
|
new webpack.EnvironmentPlugin(environment),
|
||||||
new MiniCSSExtractPlugin({
|
new MiniCSSExtractPlugin({
|
||||||
filename: "css/[name].css"
|
filename: "css/[name].[hash:7].css"
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const environment = (process.env.NODE_ENV || "development").trim();
|
const environment = (process.env.NODE_ENV || "development").trim();
|
||||||
|
const merge = require("webpack-merge");
|
||||||
|
|
||||||
if (environment === "development") {
|
if (environment === "development") {
|
||||||
module.exports = require("./config/webpack.config.dev");
|
module.exports = require("./config/webpack.config.dev");
|
||||||
} else {
|
} else {
|
||||||
module.exports = require("./config/webpack.config.prod");
|
let prodConfig = require("./config/webpack.config.prod");
|
||||||
|
module.exports = merge(prodConfig, require("./config/planetposen.config.js"));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user