-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.config.js
71 lines (71 loc) · 1.89 KB
/
webpack.base.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
const webpack = require('webpack');
const merge = require('webpack-merge');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const path = require('path');
module.exports = env => {
const { PLATFORM, VERSION } = env;
console.log(PLATFORM, VERSION);
return merge([
{
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
PLATFORM === 'production'
? MiniCssExtractPlugin.loader
: 'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
localIdentName: '[name]_[local]_[hash:base64]',
camelCase: true
}
},
'sass-loader'
]
},
{
text: /\.(png|jpg|jpeg|gif)$/,
exclude: /node_modules/,
use: 'file-loader'
}
]
},
entry: {
app: './src/index.js'
},
devServer: {
contentBase: './dist'
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HTMLWebpackPlugin({
title: 'my html webpack',
filename: './index.html',
template: './src/index.html'
}),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(VERSION),
'process.env.PLATFORM': JSON.stringify(PLATFORM)
})
]
}
]);
};