-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.base.conf.js
146 lines (132 loc) · 3.54 KB
/
webpack.base.conf.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const fs = require('fs')
const webpack = require('webpack')
const config = require('../config')
const WriteFileWebpackPlugin = require('write-file-webpack-plugin')
const SvgStore = require('webpack-svgstore-plugin')
const paths = require('../config/paths')
const commonExcludes = require('../lib/common-excludes')
const isDevServer = process.argv.find(v => v.includes('serve'))
/**
* Return an array of ContextReplacementPlugin to use.
* Omit the __appvendors__ replacement if the directory does not exists.
*
* @see https://webpack.js.org/plugins/context-replacement-plugin/#newcontentcallback
*/
const contextReplacementPlugins = () => {
// Given a request path, return a function that accepts a context and modify it's request.
const replaceCtxRequest = request => context => Object.assign(context, { request })
const plugins = [
new webpack.ContextReplacementPlugin(/__appsrc__/, replaceCtxRequest(paths.src))
]
if (fs.existsSync(paths.vendors)) {
return [
...plugins,
new webpack.ContextReplacementPlugin(/__appvendors__/, replaceCtxRequest(paths.vendors))
]
}
return plugins
}
module.exports = {
context: paths.src,
entry: config.paths.entrypoints,
output: {
filename: '[name].[hash].js',
path: config.paths.assetsOutput
},
resolveLoader: {
modules: [config.paths.lib, 'node_modules']
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: commonExcludes(),
loader: 'eslint-loader',
options: {
configFile: config.paths.eslintrc
}
},
{
test: /\.js$/,
exclude: commonExcludes(),
loader: 'babel-loader',
options: {
presets: [
['env', {
targets: {
browsers: ['last 2 versions', 'safari >= 7']
},
modules: false
}]
]
}
},
{
test: /\.js$/,
exclude: commonExcludes(),
loader: 'hmr-alamo-loader'
},
{
test: /fonts\/.*\.(eot|svg|ttf|woff|woff2)$/,
exclude: /node_modules/,
loader: 'file-loader'
},
{
test: config.regex.images,
exclude: commonExcludes(),
use: [
{ loader: 'file-loader', options: { name: '[name].[hash].[ext]' } },
{ loader: 'img-loader' }
]
},
{
test: config.regex.static,
// excluding layout/theme.liquid as it's also being emitted by the HtmlWebpackPlugin
exclude: commonExcludes('layout/theme.liquid'),
loader: 'file-loader',
options: {
name: '../[path][name].[ext]'
}
},
{
test: /assets\/vendors\//,
exclude: /node_modules/,
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
},
{
test: /layout\/theme\.liquid$/,
exclude: commonExcludes(),
loader: 'raw-loader'
},
{
test: /\.liquid$/,
exclude: commonExcludes(),
loader: `extract-loader!liquid-loader?dev-server=${isDevServer ? 'true' : 'false'}`
}
]
},
plugins: [
...contextReplacementPlugins(),
new WriteFileWebpackPlugin({
test: /\.(png|svg|jpg|gif|scss)/,
useHashIndex: true,
log: false
}),
new WriteFileWebpackPlugin({
test: /^(?:(?!hot-update.json$).)*\.(liquid|json)$/,
useHashIndex: true,
log: false
}),
new SvgStore({
svgoOptions: {
plugins: [
{ removeTitle: true }
]
}
})
]
}