-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.client.config.js
121 lines (111 loc) · 3.35 KB
/
webpack.client.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* eslint-env node */
/* eslint-disable import/no-commonjs,import/no-nodejs-modules */
const webpack = require("webpack");
const merge = require("webpack-merge");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const FriendlyErrorsPlugin = require("friendly-errors-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require('html-webpack-plugin');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV =
process.argv.indexOf("-p") !== -1 ? "production" : "development";
}
const mode = process.env.NODE_ENV;
const ENTRY_DIR = '/client_src';
const OUTPUT_DIR = (mode === "development") ? '/' : "/static";
const nodeModules = path.resolve(__dirname, 'node_modules');
const baseConfig = {
mode,
entry: {
"main": path.join(__dirname, ENTRY_DIR, 'main.js'),
},
output: {
filename: "[name].bundle.js",
path: path.join(__dirname, OUTPUT_DIR),
publicPath: "/"
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.vue$/,
loader: "vue-loader",
include: path.join(__dirname, ENTRY_DIR),
options: {
loaders: {
scss: ["style-loader", "css-loader", "sass-loader"]
}
}
},
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.(png|jpg)$/,
loader: "url-loader"
},
{
test: /\.html$/,
loader: 'html-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
DEBUG_DEVTOOLS_RX: JSON.stringify(process.env.DEBUG_DEVTOOLS_RX)
}
}),
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
title: 'PixiJs Remoute Helper',
filename: 'main.html',
template: path.join(__dirname, ENTRY_DIR, 'main.html'),
})
]
};
let devConfig = baseConfig;
if (process.env.NODE_ENV === "development") {
devConfig = merge(baseConfig, {
devtool: "source-map",
plugins: [new FriendlyErrorsPlugin()]
});
}
const isDevServer = process.argv.find(
arg => arg.indexOf("webpack-dev-server") > -1
);
let webpackConfig = devConfig;
if (isDevServer) {
webpackConfig = merge(devConfig, {
entry: {
"libs": path.join(nodeModules, 'pixi.js/dist', 'pixi.min.js'),
},
output: {
path: OUTPUT_DIR,
},
plugins: [
new webpack.DefinePlugin({
"process.env.DEV_SERVER": "true"
}),
],
devServer: {
port: process.env.PORT || 8080,
contentBase: path.join(__dirname, 'example'),
publicPath: OUTPUT_DIR,
// noInfo: false
}
});
}
module.exports = webpackConfig;