-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.server.config.js
executable file
·102 lines (94 loc) · 3.01 KB
/
webpack.server.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
'use strict';
// Helper: root(), and rootDir() are defined at the bottom
var path = require('path');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
// --optimize-dedupe not needed https://webpack.js.org/guides/migrating/#dedupeplugin-has-been-removed
// --optimize-occurence-order is on by default
// https://webpack.js.org/guides/migrating/#occurrenceorderplugin-is-now-on-by-default
/**
* Env
* Get npm lifecycle event to identify the environment
*/
var ENV = process.env.npm_lifecycle_event;
const serverConfig = {
node: {
__dirname: true
},
entry: {
server: "./src/server/index.js"
},
target: "node",
output: {
path: __dirname,
filename: "[name].js",
libraryTarget: "commonjs2"
},
devtool: "cheap-module-source-map",
module: {
rules: [
{
test: [/\.svg$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: "file-loader",
options: {
name: "public/media/[name].[ext]",
publicPath: url => url.replace(/public/, ""),
emit: false
}
},
{
test: /\.less$/,
use: [{loader: 'style-loader'},
{loader: 'css-loader'},
{loader: 'postcss-loader'},
{loader: 'less-loader'}]
},
// {
// test: /\.(css|scss)$/,
// use: [
// {loader: 'style-loader', query: {sourceMap: ENV !== 'prebuild'}},
// {loader: 'css-loader', query: {sourceMap: ENV !== 'prebuild'}},
// {loader: 'postcss-loader', query: {sourceMap: ENV !== 'prebuild'}},
// {
// loader: 'sass-loader',
// options: {
// sourceMap: ENV !== 'prebuild'
// },
// }]
// },
{
test: /\.(css|scss)$/,
use: ExtractTextPlugin.extract({
fallback:'style-loader',
use:['css-loader', 'postcss-loader', 'sass-loader'],
})
},
{
test: /js$/,
exclude: /(node_modules)/,
loader: "babel-loader",
options: {
presets: [
'es2015',
'stage-2',
'react'
]
}
}
]
},
plugins: [
new ExtractTextPlugin({filename:'app.bundle.css'}),
]
};
const targets = ['node'].map((target) => {
return webpackMerge(serverConfig, {
target: target,
output: {
path: path.resolve(__dirname, 'dist/server'),
filename: 'server.js',
// libraryTarget: 'commonjs2'
}
});
});
module.exports = targets;