-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
123 lines (118 loc) · 3.82 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
120
121
122
123
'use strict';
var shell = require('shelljs');
var path = require('path');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var cwd = process.cwd();
var { CleanWebpackPlugin } = require('clean-webpack-plugin');
var packageName = '';
var jsFiles = {};
var scssFiles = {};
process.argv.forEach((val, index) => {
if (val === 'entryPackageName') {
packageName = process.argv[index + 1];
var cssFilesTmp = shell.ls(path.join(cwd, `./cartridges/${packageName}/cartridge/client/**/scss/**/*.scss`));
cssFilesTmp.forEach(filePath => {
var name = path.basename(filePath, '.scss');
if (name.indexOf('_') !== 0) {
let location = path.relative(path.join(cwd, `./cartridges/${packageName}/cartridge/client`), filePath);
location = location.substr(0, location.length - 5).replace('scss', 'css');
scssFiles[location] = filePath;
}
});
var jsFilesTmp = shell.ls(path.join(cwd, `./cartridges/${packageName}/cartridge/client/**/js/*.js`));
jsFilesTmp.forEach(filePath => {
let location = path.relative(path.join(cwd, `./cartridges/${packageName}/cartridge/client`), filePath);
location = location.substr(0, location.length - 3);
jsFiles[location] = filePath;
});
}
});
var outputPath = './cartridges/' + packageName + '/cartridge/static';
console.log("scssFiles: ", scssFiles);
console.log("jsFiles: ", jsFiles);
module.exports = [{
mode: 'production',
name: 'js',
entry: jsFiles,
output: {
path: path.resolve(outputPath),
filename: '[name].js'
},
module: {
rules: [
{
test: /bootstrap(.)*\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/env'],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
cacheDirectory: true
}
}
}
]
},
resolve: {
alias: {
jquery: path.resolve(__dirname, '../storefront-reference-architecture/node_modules/jquery')
}
}
},
{
mode: 'production',
name: 'scss',
entry: scssFiles,
output: {
path: path.resolve(outputPath),
filename: '[name].tmp'
},
module: {
rules: [{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
['autoprefixer', {}]
]
}
}
},
{
loader: 'sass-loader',
options: {
includePaths: [
path.resolve(
process.cwd(),
'../storefront-reference-architecture/node_modules/'
),
path.resolve('node_modules')
]
}
}
]
}]
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].css' }),
new CleanWebpackPlugin(
{
cleanOnceBeforeBuildPatterns: ['js/*.js', 'css/*.css'],
cleanAfterEveryBuildPatterns: ['**/*.tmp'],
protectWebpackAssets: false,
verbose: true,
dry: false
},
)
]
}];