UNPKG

3.29 kBJavaScriptView Raw
1const pathConfig = require('config').get('path')
2const path = require('path')
3const webpack = require('webpack')
4const VueLoaderPlugin = require('vue-loader/lib/plugin')
5const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
6const nodeExternals = require('webpack-node-externals')
7const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8const MiniCssExtractPlugin = require('mini-css-extract-plugin')
9// const extractCSS = require('./extract.js')
10const { alias } = require('./alias')
11const { serverEntry } = require('./entry')
12
13const { publicPath } = require('./output.js')
14
15const 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 // do not externalize CSS files in case we need to import it from a dep
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
119module.exports = { webpackConfig }