2022-04-17 00:39:10 +00:00
|
|
|
const webpack = require('webpack');
|
2022-08-19 16:15:57 +00:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
2022-04-17 00:39:10 +00:00
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
|
|
|
|
exports.setupSass = paths => ({
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
|
|
include: paths,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.extractCSS = paths => ({
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
2022-08-19 16:15:57 +00:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
postcssOptions: {
|
|
|
|
plugins: [
|
2022-04-17 00:39:10 +00:00
|
|
|
autoprefixer({
|
2022-08-19 16:15:57 +00:00
|
|
|
browsers: ['last 2 versions', '>1%'],
|
2022-04-17 00:39:10 +00:00
|
|
|
cascade: false,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2022-08-19 16:15:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
},
|
|
|
|
],
|
2022-04-17 00:39:10 +00:00
|
|
|
include: paths,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2022-08-19 16:15:57 +00:00
|
|
|
new MiniCssExtractPlugin({
|
2022-04-17 00:39:10 +00:00
|
|
|
filename: '[name].css',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.devServer = options => ({
|
|
|
|
devServer: {
|
2022-08-19 16:15:57 +00:00
|
|
|
static:{
|
|
|
|
directory: __dirname,
|
|
|
|
},
|
2022-04-17 00:39:10 +00:00
|
|
|
historyApiFallback: true,
|
|
|
|
hot: false,
|
|
|
|
host: options.host,
|
|
|
|
port: options.port,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.minify = () => ({
|
2022-08-19 16:15:57 +00:00
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
parallel: false,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2022-04-17 00:39:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
exports.setFreeVariable = (key, value) => {
|
|
|
|
const env = {};
|
|
|
|
env[key] = JSON.stringify(value);
|
|
|
|
|
|
|
|
return {
|
|
|
|
plugins: [new webpack.DefinePlugin(env)],
|
|
|
|
};
|
|
|
|
};
|