blessing-skin-server/webpack.config.js

164 lines
4.5 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')
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: {
2019-04-27 22:06:09 +08:00
index: './resources/assets/src/index.ts',
2019-04-08 14:42:40 +08:00
'check-updates': './resources/assets/src/scripts/check-updates.ts',
2019-03-15 11:42:41 +08:00
style: [
'bootstrap/dist/css/bootstrap.min.css',
2019-03-27 10:50:17 +08:00
'admin-lte/dist/css/alt/AdminLTE-without-plugins.min.css',
2019-03-25 22:01:57 +08:00
'element-ui/lib/theme-chalk/base.css',
2019-03-28 16:37:01 +08:00
'./resources/assets/src/styles/element.scss',
2019-03-15 11:42:41 +08:00
'@fortawesome/fontawesome-free/css/fontawesome.min.css',
'@fortawesome/fontawesome-free/css/regular.min.css',
2019-03-15 11:42:41 +08:00
'@fortawesome/fontawesome-free/css/solid.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: [
{
2019-03-17 21:09:46 +08:00
test: /\.(t|j)s$/,
2019-03-15 11:42:41 +08:00
exclude: /node_modules/,
2019-05-07 23:56:25 +08:00
use: [
'cache-loader',
{
loader: 'babel-loader',
options: {
plugins: [
['babel-plugin-import', {
libraryName: 'element-ui',
libraryDirectory: 'lib',
camel2DashComponentName: true,
2019-05-08 11:41:49 +08:00
style: name => {
if (name.includes('locale')) {
return false
}
return `${name.replace('lib/', 'lib/theme-chalk/')}.css`
},
2019-05-07 23:56:25 +08:00
}],
],
},
},
],
2019-03-15 11:42:41 +08:00
},
{
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,
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
},
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({
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
}),
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',
]),
2019-03-31 13:12:56 +08:00
new ManifestPlugin(),
2019-03-15 11:42:41 +08:00
],
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,
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