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')
|
2019-09-20 20:12:59 +08:00
|
|
|
const TerserJSPlugin = require('terser-webpack-plugin')
|
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
2019-03-15 11:42:41 +08:00
|
|
|
const WebpackBar = require('webpackbar')
|
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-09-19 22:13:25 +08:00
|
|
|
'language-chooser': './resources/assets/src/scripts/language-chooser.ts',
|
2019-03-15 11:42:41 +08:00
|
|
|
style: [
|
|
|
|
'bootstrap/dist/css/bootstrap.min.css',
|
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
|
|
|
],
|
2019-03-28 16:37:01 +08:00
|
|
|
setup: './resources/assets/src/styles/setup.styl',
|
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-01-27 15:47:24 +08:00
|
|
|
use: 'ts-loader',
|
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
|
|
|
{
|
|
|
|
test: /views.*\.styl$/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 2,
|
|
|
|
modules: {
|
|
|
|
localIdentName: devMode ? '[name]__[local]' : '[hash:base64]',
|
|
|
|
},
|
|
|
|
localsConvention: 'dashes',
|
|
|
|
esModule: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'postcss-loader',
|
|
|
|
'stylus-loader',
|
|
|
|
],
|
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
{
|
2019-12-01 18:08:21 +08:00
|
|
|
test: /(node_modules.*)\.css$/,
|
2019-03-15 11:42:41 +08:00
|
|
|
use: [
|
2019-09-20 20:12:59 +08:00
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /(common|home|setup)\.styl$/,
|
|
|
|
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',
|
|
|
|
},
|
2019-03-15 11:42:41 +08:00
|
|
|
},
|
2019-09-20 20:12:59 +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-03-15 11:42:41 +08:00
|
|
|
config.plugins.push(new WebpackBar())
|
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
|