blessing-skin-server/webpack.config.js

158 lines
4.9 KiB
JavaScript
Raw Normal View History

2018-07-29 15:31:54 +08:00
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
2018-08-04 09:12:04 +08:00
const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin');
2018-08-04 09:02:45 +08:00
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
2018-07-29 15:31:54 +08:00
const WebpackBar = require('webpackbar');
2018-08-09 09:31:34 +08:00
const devMode = process.env.WEBPACK_SERVE;
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 = {
mode: devMode ? 'development' : 'production',
2018-07-29 15:31:54 +08:00
entry: {
index: './resources/assets/src/index.js',
polyfill: './resources/assets/src/js/polyfill.js',
style: [
'bootstrap/dist/css/bootstrap.min.css',
'admin-lte/dist/css/AdminLTE.min.css',
'bootstrap-fileinput/css/fileinput.min.css',
2018-08-08 12:30:50 +08:00
'@fortawesome/fontawesome-free/css/fontawesome.min.css',
'@fortawesome/fontawesome-free/css/regular.min.css',
'@fortawesome/fontawesome-free/css/solid.min.css',
2018-07-29 15:31:54 +08:00
'icheck/skins/square/blue.css',
'toastr/build/toastr.min.css',
2018-08-04 10:22:16 +08:00
'sweetalert2/dist/sweetalert2.min.css',
2018-07-30 11:24:36 +08:00
'./resources/assets/src/stylus/common.styl',
2018-08-07 09:25:20 +08:00
],
2018-08-08 18:17:11 +08:00
home: './resources/assets/src/stylus/home.styl',
'langs/en': './resources/lang/en/front-end.js',
'langs/zh_CN': './resources/lang/zh_CN/front-end.js',
2018-07-29 15:31:54 +08:00
},
output: {
path: __dirname + '/public',
filename: '[name].js',
chunkFilename: devMode
? '[id].js'
2018-08-11 09:16:53 +08:00
: '[id].[contenthash:7].js'
2018-07-29 15:31:54 +08:00
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
2018-08-02 23:02:13 +08:00
use: [
'cache-loader',
'babel-loader'
]
2018-07-29 15:31:54 +08:00
},
{
test: /\.vue$/,
2018-08-02 23:02:13 +08:00
use: [
'cache-loader',
'vue-loader'
]
2018-07-29 15:31:54 +08:00
},
{
2018-07-30 09:45:37 +08:00
test: /\.(css|styl(us)?)$/,
2018-07-29 15:31:54 +08:00
exclude: /node_modules/,
use: [
2018-07-30 09:45:37 +08:00
'vue-style-loader',
2018-07-29 15:31:54 +08:00
{ loader: 'css-loader', options: { importLoaders: 2 } },
'postcss-loader',
'stylus-loader'
]
},
{
test: /node_modules.*\.css$/,
2018-08-04 10:22:16 +08:00
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { importLoaders: 1 } },
'csso-loader?-comments',
]
2018-07-29 15:31:54 +08:00
},
2018-07-30 11:24:36 +08:00
{
2018-08-07 09:25:20 +08:00
test: /(common|home)\.styl$/,
2018-07-30 11:24:36 +08:00
use: [
MiniCssExtractPlugin.loader,
2018-08-04 10:22:16 +08:00
{ loader: 'css-loader', options: { importLoaders: 3 } },
'csso-loader',
2018-07-30 11:24:36 +08:00
'postcss-loader',
'stylus-loader'
]
},
2018-08-08 18:17:11 +08:00
{
test: /\.yml$/,
use: [
'json-loader',
'yaml-loader'
]
},
2018-07-29 15:31:54 +08:00
{
2018-08-03 10:35:06 +08:00
test: /\.(png|jpg|gif)$/,
2018-07-29 15:31:54 +08:00
loader: 'url-loader',
options: {
limit: 8192
}
2018-08-03 10:35:06 +08:00
},
{
test: /\.(svg|woff2?|eot|ttf)$/,
loader: 'file-loader'
2018-07-29 15:31:54 +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
},
2018-08-09 17:07:20 +08:00
{
from: 'node_modules/admin-lte/dist/css/skins/_all-skins.min.css',
to: 'skins',
flatten: true
},
2018-08-08 15:30:26 +08:00
'node_modules/chart.js/dist/Chart.min.js',
2018-07-29 15:31:54 +08:00
]),
2018-08-04 09:02:45 +08:00
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: devMode ? 'server' : 'static'
}),
2018-07-29 15:31:54 +08:00
],
2018-08-02 23:02:13 +08:00
optimization: {
minimizer: [
2018-08-04 09:12:04 +08:00
new UglifyJsWebpackPlugin({
parallel: true,
2018-08-02 23:02:13 +08:00
cache: true,
2018-08-04 09:12:04 +08:00
sourceMap: false,
extractComments: {
filename: 'LICENSES'
},
uglifyOptions: {
output: {
comments: /^\**!|@preserve|@license|@cc_on/
}
}
2018-08-02 23:02:13 +08:00
})
]
},
2018-07-29 15:31:54 +08:00
resolve: {
extensions: ['.js', '.vue', '.json']
},
devtool: devMode ? 'cheap-module-eval-source-map' : false,
2018-07-29 18:56:07 +08:00
stats: 'errors-only'
2018-08-08 18:17:11 +08:00
};
2018-08-09 09:31:34 +08:00
if (!devMode) {
config.plugins.push(new WebpackBar());
}
2018-08-08 18:17:11 +08:00
module.exports = config;