-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebpack.config.js
87 lines (82 loc) · 2.59 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
const webpack = require('webpack');
const {VueLoaderPlugin} = require('vue-loader');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin').CleanWebpackPlugin;
const fs = require('fs')
const packageJson = fs.readFileSync('./package.json')
const version = JSON.parse(packageJson).version || 0
function getPlugins(mode, argv) {
return [
new webpack.ProgressPlugin(),
new VueLoaderPlugin(),
new CleanWebpackPlugin({verbose: true}),
new MiniCssExtractPlugin({
filename: 'css/[name].css'
}),
new webpack.DefinePlugin({
'process.env': {
PACKAGE_VERSION: '"' + version + '"',
IS_DEVELOPMENT: argv.mode === 'development'
},
})
];
}
module.exports = (mode, argv) => {
const config = {
performance: {
hints: false
},
entry: {
dev_tools: [
__dirname + '/cartridge/client/default/js/dev_tools.js',
__dirname + '/cartridge/client/default/scss/dev_tools.scss',
],
},
output: {
filename: 'js/[name].js',
path: __dirname + '/cartridge/static/default'
},
module: {
rules: [
{
test: /\.vue$/,
exclude: /node_modules/,
use: 'vue-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{loader: 'css-loader', options: {url: false, sourceMap: argv.mode === 'development'}},
{loader: 'sass-loader', options: {sourceMap: argv.mode === 'development'}}
]
}
]
},
resolve: {
extensions: ['.js', '.vue'],
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
}
},
plugins: getPlugins(mode, argv)
};
if (argv.mode === 'development') {
config.devtool = 'source-map';
}
return config;
};