-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.config.js
executable file
·85 lines (82 loc) · 2.8 KB
/
webpack.base.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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const AssetsPlugin = require('assets-webpack-plugin');
const dev = process.env.NODE_ENV === 'dev';
const srcFolder = path.resolve(__dirname, 'src');
const srcServerFolder = `${srcFolder}/server`;
const srcClientFolder = `${srcFolder}/client`;
const srcClientImgFolder = `${srcClientFolder}/img`;
let config = {
context: srcFolder,
// watch any modification and make sure the app is rebuild in dev
watch: true,
// be able to debug the source files in dev (and not the bundle.js)
devtool: 'cheap-module-eval-source-map',
module: {
rules: [
// the babel-loader converts new js features into old ones (es6, react jsx...)
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
// load fonts so they can be used in the css
{
test: /\.(eot|ttf|woff|svg)$/,
use: {
loader: "file-loader",
options: {
outputPath: 'public/font/',
publicPath: '/',
name: '[name].[hash].[ext]'
}
},
},
// load the css
{
test: /\.(css)$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: {
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: !dev
}
}
})
}
],
},
plugins: [
// get a css file and not the style in the middle of the html
new ExtractTextPlugin({
filename: 'css/[name].[contenthash].css'
}),
// copy the images to the dist folder
new CopyWebpackPlugin([
{ from: srcClientImgFolder, to: 'img'},
]),
// creates a json file with the path to css/js so we are able to use hashes on the output files
new AssetsPlugin({
path: srcServerFolder,
fullPath: false
}),
// set global variables
new webpack.DefinePlugin({
APP: JSON.stringify(dev)
})
],
resolve: {
alias: {
server: path.resolve(__dirname, 'src/server/'),
client: path.resolve(__dirname, 'src/client/'),
shared: path.resolve(__dirname, 'src/shared/')
}
}
};
module.exports = {
config
};