-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (106 loc) · 2.6 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
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const NODE_ENV = process.env.NODE_ENV;
const PROJECTS = {
proj1:"'Proj1'",
proj2:"'Proj2'"
}
let nameOfProject = (projName)=> console.log('building with param',projName ) || PROJECTS[projName] ? PROJECTS[projName] : PROJECTS['proj1']
const setPath = function(folderName) {
return path.join(__dirname, folderName);
}
const buildingForLocal = () => {
return (NODE_ENV === 'development');
};
const config = {
mode: 'production',
output: {
path: buildingForLocal() ? path.resolve(__dirname) : setPath('dist'),
publicPath: '/',
filename: buildingForLocal() ? 'js/[name].js' : 'js/[name].[hash].js'
},
optimization:{
runtimeChunk: false,
splitChunks: {
chunks: "all",
}
},
resolveLoader: {
modules: [setPath('node_modules')]
},
devServer: {
historyApiFallback: true,
noInfo: false
},
devtool:'cheap-source-map',
plugins: [
new webpack.DefinePlugin({
//this will create a variable which will be replaced
//by any instance of its key accross the project
__PROJECT_NAME__:nameOfProject(process.env.VENDOR),
})
],
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // Use the full build
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader'
}
}
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: [{
loader: "babel-loader",
options: { presets: ['env'] }
}]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
},
{
test: /\.scss$/,
use: !buildingForLocal() ?
[
MiniCssExtractPlugin.loader,
"css-loader", 'sass-loader'
] :
[{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
}]
},
{
test: /\.svg$/,
loader: 'svg-sprite-loader'
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
query: {
name: '[name].[ext]?[hash]',
useRelativePath: buildingForLocal()
}
}
]
},
};
module.exports = config;