blessing-skin-server/webpack.config.js

148 lines
4.0 KiB
JavaScript
Raw Normal View History

2020-02-07 09:59:10 +08:00
const path = require('path')
2019-03-15 11:42:41 +08:00
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserJSPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
2019-03-31 13:12:56 +08:00
const ManifestPlugin = require('webpack-manifest-plugin')
2018-07-29 15:31:54 +08:00
2019-03-17 23:10:40 +08:00
const devMode = !process.argv.includes('-p')
2018-07-29 15:31:54 +08:00
2018-08-09 09:31:34 +08:00
/** @type {import('webpack').Configuration} */
2018-08-08 18:17:11 +08:00
const config = {
2019-03-15 11:42:41 +08:00
mode: devMode ? 'development' : 'production',
entry: {
2020-01-21 10:22:20 +08:00
app: ['react-hot-loader/patch', './resources/assets/src/index.tsx'],
2019-03-15 11:42:41 +08:00
style: [
2019-11-24 14:32:58 +08:00
'admin-lte/dist/css/alt/adminlte.core.min.css',
'admin-lte/dist/css/alt/adminlte.components.min.css',
'admin-lte/dist/css/alt/adminlte.extra-components.min.css',
'admin-lte/dist/css/alt/adminlte.pages.min.css',
2020-01-16 12:33:14 +08:00
'@fortawesome/fontawesome-free/css/all.min.css',
2019-03-28 16:37:01 +08:00
'./resources/assets/src/styles/common.styl',
2019-03-15 11:42:41 +08:00
],
2020-02-01 12:44:39 +08:00
spectre: [
'spectre.css/dist/spectre.min.css',
'./resources/assets/src/fonts/minecraft.css',
'./resources/assets/src/styles/spectre.css',
],
2019-03-15 11:42:41 +08:00
},
output: {
path: `${__dirname}/public/app`,
2019-03-31 13:29:23 +08:00
filename: devMode ? '[name].js' : '[name].[contenthash:7].js',
2019-03-15 11:42:41 +08:00
chunkFilename: devMode ? '[id].js' : '[id].[contenthash:7].js',
},
module: {
rules: [
{
2020-01-16 16:14:49 +08:00
test: /\.js$/,
2019-03-15 11:42:41 +08:00
exclude: /node_modules/,
2019-12-01 18:08:21 +08:00
use: ['cache-loader', 'babel-loader'],
2019-03-15 11:42:41 +08:00
},
2020-01-16 16:14:49 +08:00
{
test: /\.tsx?$/,
2020-03-12 11:06:23 +08:00
loader: 'ts-loader',
options: {
configFile: 'tsconfig.build.json',
},
2020-01-16 16:14:49 +08:00
},
2019-03-15 11:42:41 +08:00
{
test: /\.vue$/,
use: ['cache-loader', 'vue-loader'],
},
{
2020-01-21 10:22:20 +08:00
test: /\.vue.*\.stylus$/,
2019-03-15 11:42:41 +08:00
use: [
'vue-style-loader',
{ loader: 'css-loader', options: { importLoaders: 2 } },
'postcss-loader',
'stylus-loader',
2018-08-07 09:25:20 +08:00
],
2019-03-15 11:42:41 +08:00
},
2020-01-21 10:22:20 +08:00
{
2020-03-14 16:13:56 +08:00
test: /\.module\.scss$/,
2020-01-21 10:22:20 +08:00
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 2,
modules: {
2020-01-31 15:58:37 +08:00
localIdentName: devMode ? '[name]__[local]' : '[local]__[hash:base64:5]',
2020-01-21 10:22:20 +08:00
},
esModule: true,
},
},
'postcss-loader',
2020-01-27 15:49:09 +08:00
'sass-loader',
2020-01-21 10:22:20 +08:00
],
},
2019-03-15 11:42:41 +08:00
{
2020-02-01 12:44:39 +08:00
test: /\.css$/,
2019-03-15 11:42:41 +08:00
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
2019-12-01 18:08:21 +08:00
'css-loader',
2018-07-29 15:31:54 +08:00
],
2019-03-15 11:42:41 +08:00
},
{
2020-02-01 12:44:39 +08:00
test: /(common|home)\.styl$/,
2019-03-15 11:42:41 +08:00
use: [
MiniCssExtractPlugin.loader,
2019-03-28 10:24:09 +08:00
{ loader: 'css-loader', options: { importLoaders: 2 } },
2019-03-15 11:42:41 +08:00
'postcss-loader',
'stylus-loader',
],
},
{
test: /\.(png|jpg|gif)$/,
loader: 'url-loader',
options: {
limit: 8192,
2019-02-19 17:26:38 +08:00
},
2019-03-15 11:42:41 +08:00
},
{
test: /\.(svg|woff2?|eot|ttf)$/,
2019-03-25 22:01:57 +08:00
loader: devMode ? 'url-loader' : 'file-loader',
2019-03-15 11:42:41 +08:00
},
],
noParse: /^(vue|jquery)$/,
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
2019-03-31 13:29:23 +08:00
filename: devMode ? '[name].css' : '[name].[contenthash:7].css',
chunkFilename: devMode ? '[id].css' : '[id].[contenthash:7].css',
2019-03-15 11:42:41 +08:00
}),
],
resolve: {
2020-01-21 10:22:20 +08:00
extensions: ['.js', '.ts', '.tsx', '.vue', '.json'],
alias: {
'react-dom': '@hot-loader/react-dom',
2020-02-07 09:59:10 +08:00
'@': path.resolve(__dirname, 'resources/assets/src'),
2020-01-21 10:22:20 +08:00
},
2019-03-15 11:42:41 +08:00
},
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
2019-03-15 11:42:41 +08:00
devtool: devMode ? 'cheap-module-eval-source-map' : false,
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
2019-02-19 17:26:38 +08:00
},
2019-03-15 11:42:41 +08:00
host: '0.0.0.0',
hot: true,
2019-09-20 19:43:51 +08:00
hotOnly: true,
2019-03-15 11:42:41 +08:00
stats: 'errors-only',
},
stats: 'errors-only',
}
2018-08-08 18:17:11 +08:00
2019-03-15 11:42:41 +08:00
if (devMode) {
2019-09-20 19:43:51 +08:00
config.plugins.push(new webpack.NamedModulesPlugin())
2019-03-15 11:42:41 +08:00
config.plugins.push(new webpack.HotModuleReplacementPlugin())
2019-02-19 17:26:38 +08:00
} else {
2019-09-20 19:43:51 +08:00
config.plugins.push(new ManifestPlugin())
2018-08-09 09:31:34 +08:00
}
2019-03-15 11:42:41 +08:00
module.exports = config