1 | const pathConfig = require('config').get('path')
|
2 | const path = require('path')
|
3 | const webpack = require('webpack')
|
4 | const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
5 | const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
|
6 | const nodeExternals = require('webpack-node-externals')
|
7 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
|
8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
9 |
|
10 | const { alias } = require('./alias')
|
11 | const { serverEntry } = require('./entry')
|
12 |
|
13 | const { publicPath } = require('./output.js')
|
14 |
|
15 | const webpackConfig = {
|
16 | mode: 'production',
|
17 | target: 'node',
|
18 | entry: Object.assign({ global: pathConfig.globalServer }, serverEntry),
|
19 | output: {
|
20 | filename: 'js/[name]-server.js',
|
21 | path: pathConfig.dist,
|
22 | publicPath: publicPath,
|
23 | libraryTarget: 'commonjs2'
|
24 | },
|
25 | resolve: {
|
26 | alias,
|
27 | extensions: ['.js', '.json', '.vue']
|
28 | },
|
29 | externals: nodeExternals({
|
30 |
|
31 | whitelist: /\.css$/
|
32 | }),
|
33 | module: {
|
34 | rules: [
|
35 | {
|
36 | test: /\.vue$/,
|
37 | use: [
|
38 | {
|
39 | loader: 'vue-loader',
|
40 | options: {
|
41 | compilerOptions: {
|
42 | preserveWhitespace: false
|
43 | },
|
44 | presets: [['env', { modules: false }]],
|
45 | plugins: ['syntax-dynamic-import'],
|
46 | loaders: {
|
47 | css: ['vue-style-loader', 'css-loader'],
|
48 | sass: ['vue-style-loader', 'css-loader', 'sass-loader'],
|
49 | scss: ['vue-style-loader', 'css-loader', 'sass-loader'],
|
50 | js: {
|
51 | loader: 'babel-loader',
|
52 | options: {
|
53 | presets: ['@babel/preset-env']
|
54 | }
|
55 | }
|
56 | }
|
57 | }
|
58 | }
|
59 | ]
|
60 | },
|
61 | {
|
62 | test: /\.js$/,
|
63 | use: [
|
64 | {
|
65 | loader: 'babel-loader',
|
66 | options: {
|
67 | presets: ['@babel/preset-env'],
|
68 | plugins: ['syntax-dynamic-import']
|
69 | }
|
70 | }
|
71 | ]
|
72 | },
|
73 | {
|
74 | test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf|otf)(\?.*)?$/,
|
75 | use: [
|
76 | {
|
77 | loader: 'url-loader',
|
78 | options: {
|
79 | limit: 10000,
|
80 | name: 'image/[name].[hash].[ext]'
|
81 | }
|
82 | }
|
83 | ]
|
84 | },
|
85 | {
|
86 | test: /\.css$/,
|
87 | use: [MiniCssExtractPlugin.loader, 'css-loader']
|
88 | },
|
89 | {
|
90 | test: /\.scss$/,
|
91 | use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
|
92 | },
|
93 | {
|
94 | test: /\.sass$/,
|
95 | use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
|
96 | }
|
97 | ]
|
98 | },
|
99 | plugins: [
|
100 | new VueLoaderPlugin(),
|
101 | new MiniCssExtractPlugin({
|
102 | filename: 'css/[name].[contenthash].css'
|
103 | }),
|
104 | new webpack.DefinePlugin({
|
105 | 'process.env.NODE_ENV': '"production"',
|
106 | 'process.env.buildTime': JSON.stringify(Date.now())
|
107 | }),
|
108 | new webpack.DllReferencePlugin({
|
109 | manifest: require(`${pathConfig.dll}/vendor.json`)
|
110 | }),
|
111 | new VueSSRServerPlugin(),
|
112 | new FriendlyErrorsPlugin()
|
113 | ],
|
114 | optimization: {
|
115 | splitChunks: {}
|
116 | }
|
117 | }
|
118 |
|
119 | module.exports = { webpackConfig }
|