-
Notifications
You must be signed in to change notification settings - Fork 36
/
webpack.config.js
119 lines (108 loc) · 2.61 KB
/
webpack.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
'use strict'
const { INIT_CWD, NODE_ENV } = process.env
const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const autoprefixer = require('autoprefixer')
const cssnano = require('cssnano')
const devMode = NODE_ENV !== 'production'
const { webpackOutput } = require(path.join(INIT_CWD, './package.json'))
const externals = require('./@ecomplus/storefront-template/webpack.externals')
const templatePath = path.join(__dirname, './node_modules/@ecomplus/storefront-snapshot')
const output = {
library: 'widget',
libraryTarget: 'umd',
libraryExport: 'default',
path: path.resolve(INIT_CWD, 'dist'),
filename: 'widget.min.js',
publicPath: devMode ? '/' : '/assets/vendor/',
...webpackOutput
}
output.chunkFilename = output.filename.replace('.min.js', '.[name].min.js')
const baseModuleRules = [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compilerOptions: {
whitespace: devMode ? 'preserve' : 'condense'
}
}
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: 'file-loader'
},
{
test: /\.s?css$/,
use: [
'vue-style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
ident: 'postcss',
minimize: !devMode,
plugins: [
autoprefixer(),
cssnano({ preset: 'default' })
]
}
}
},
'sass-loader'
]
}
]
const moduleRulesWithPolyfill = baseModuleRules.concat([{
test: /^(.(?!\.min.js$))+\.m?js$/,
loader: 'babel-loader'
}])
const generalConfig = {
mode: devMode ? 'development' : 'production',
entry: path.resolve(INIT_CWD, devMode ? '__tests__/index.js' : 'src/index.js'),
output,
devServer: {
contentBase: templatePath,
stats: 'minimal',
port: 9128,
open: true
},
stats: {
colors: true
},
resolve: {
alias: {
'#components': '@ecomplus/storefront-components/src'
}
},
devtool: 'source-map',
plugins: [
new VueLoaderPlugin()
],
module: {
rules: moduleRulesWithPolyfill
},
externals
}
if (devMode) {
generalConfig.plugins.push(new HtmlWebpackPlugin({
template: path.resolve(templatePath, 'index.html')
}))
}
module.exports = devMode
? generalConfig
: [
generalConfig,
{
...generalConfig,
output: {
...output,
libraryTarget: 'var',
filename: output.filename.replace('.min.js', '.var.min.js'),
path: path.join(output.path, 'public')
},
externals
}
]