2019-02-27 00:07:00 +07:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const path = require("path");
|
|
|
|
const merge = require("webpack-merge");
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const PreloadWebpackPlugin = require("preload-webpack-plugin");
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
|
|
// const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
|
|
|
|
|
|
|
const root = path.join(__dirname, "..");
|
2019-03-15 05:29:19 +07:00
|
|
|
const prod = process.env.NODE_ENV === "production" || process.env.CI === "true";
|
2019-02-27 00:07:00 +07:00
|
|
|
|
|
|
|
module.exports = (options = {}) => merge(
|
|
|
|
require("./webpack.general.config")(options), {
|
2019-03-15 05:58:12 +07:00
|
|
|
devtool: prod ? "none" : "cheap-module-eval-source-map",
|
2019-02-27 00:07:00 +07:00
|
|
|
mode: prod ? "production" : "development",
|
|
|
|
entry: prod ? options.entry : [
|
|
|
|
"webpack-hot-middleware/client?reload=true&quiet=true",
|
|
|
|
options.entry,
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
// This is required otherwise it'll fail to resolve CSS in common.
|
|
|
|
include: root,
|
|
|
|
use: [{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
}, {
|
|
|
|
loader: "css-loader",
|
|
|
|
}, {
|
|
|
|
loader: "sass-loader",
|
|
|
|
}],
|
|
|
|
}, {
|
2019-04-02 03:20:39 +07:00
|
|
|
test: /\.(png|ttf|woff|eot|woff2)$/,
|
2019-02-27 00:07:00 +07:00
|
|
|
use: [{
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "[path][name].[ext]",
|
|
|
|
},
|
|
|
|
}],
|
2019-04-02 03:20:39 +07:00
|
|
|
}, {
|
|
|
|
test: /\.svg$/,
|
|
|
|
loader: 'url-loader'
|
2019-02-27 00:07:00 +07:00
|
|
|
}],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: "[name].css",
|
|
|
|
chunkFilename: "[id].css",
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: options.template,
|
|
|
|
}),
|
|
|
|
new PreloadWebpackPlugin({
|
|
|
|
rel: "preload",
|
|
|
|
as: "script",
|
|
|
|
}),
|
|
|
|
].concat(prod ? [] : [
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
]),
|
|
|
|
target: "web",
|
|
|
|
});
|