blessing-skin-server/webpack.config.js

149 lines
3.9 KiB
JavaScript
Raw Normal View History

2019-03-15 16:50:16 +08:00
/* eslint-disable import/no-extraneous-dependencies */
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 CopyWebpackPlugin = require('copy-webpack-plugin')
const WebpackBar = require('webpackbar')
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: {
index: './resources/assets/src/index.js',
style: [
'bootstrap/dist/css/bootstrap.min.css',
'admin-lte/dist/css/AdminLTE.min.css',
2019-03-25 22:01:57 +08:00
'element-ui/lib/theme-chalk/base.css',
'./resources/assets/src/element.scss',
2019-03-15 11:42:41 +08:00
'@fortawesome/fontawesome-free/css/fontawesome.min.css',
'@fortawesome/fontawesome-free/css/regular.min.css',
'@fortawesome/fontawesome-free/css/solid.min.css',
'./resources/assets/src/stylus/common.styl',
],
setup: './resources/assets/src/stylus/setup.styl',
'langs/en': './resources/lang/en/front-end.js',
'langs/zh_CN': './resources/lang/zh_CN/front-end.js',
},
output: {
path: `${__dirname}/public/app`,
filename: '[name].js',
chunkFilename: devMode ? '[id].js' : '[id].[contenthash:7].js',
},
module: {
rules: [
{
2019-03-17 21:09:46 +08:00
test: /\.(t|j)s$/,
2019-03-15 11:42:41 +08:00
exclude: /node_modules/,
use: ['cache-loader', 'babel-loader'],
},
{
test: /\.vue$/,
use: ['cache-loader', 'vue-loader'],
},
{
test: /\.(css|styl(us)?)$/,
exclude: /node_modules/,
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
},
{
2019-03-25 22:01:57 +08:00
test: /((node_modules.*)|element)\.(sa|sc|c)ss$/,
2019-03-15 11:42:41 +08:00
use: [
2019-03-25 22:01:57 +08:00
devMode ? 'style-loader?hmr=true' : MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { importLoaders: 2 } },
'postcss-loader',
'sass-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,
{ loader: 'css-loader', options: { importLoaders: 3 } },
'csso-loader',
'postcss-loader',
'stylus-loader',
],
},
{
2019-03-17 23:10:40 +08:00
test: /\.ya?ml$/,
2019-03-15 11:42:41 +08:00
use: ['json-loader', 'yaml-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
},
2019-03-17 23:10:40 +08:00
{
test: require.resolve('jquery'),
use: [
{
loader: 'expose-loader',
options: 'jQuery',
},
{
loader: 'expose-loader',
options: '$',
},
],
},
2019-03-15 11:42:41 +08:00
],
noParse: /^(vue|jquery)$/,
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new CopyWebpackPlugin([
{
from: 'node_modules/admin-lte/dist/css/skins/skin-*.min.css',
to: 'skins',
flatten: true,
},
{
2019-03-17 21:09:46 +08:00
from: 'node_modules/admin-lte/dist/css/skins/_all-skins.min.css',
2019-03-15 11:42:41 +08:00
to: 'skins',
flatten: true,
},
'resources/assets/src/images/bg.jpg',
'resources/assets/src/images/favicon.ico',
]),
],
resolve: {
2019-03-17 21:09:46 +08:00
extensions: ['.js', '.ts', '.vue', '.json'],
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,
publicPath: '/public/',
stats: 'errors-only',
},
stats: 'errors-only',
}
2018-08-08 18:17:11 +08:00
2019-03-15 11:42:41 +08:00
if (devMode) {
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())
2018-08-09 09:31:34 +08:00
}
2019-03-15 11:42:41 +08:00
module.exports = config