-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
95 lines (93 loc) · 2.15 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
const path = require('path');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './src/js/main.js',
output: {
path: path.join(__dirname, './'),
filename: 'assets/js/[name].js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
include: path.join(__dirname, './src'),
loader: 'eslint-loader',
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.js$/,
include: path.join(__dirname, './src'),
loader: 'babel-loader'
},
{
test: /\.css$/,
loader: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: {
loader: 'url-loader',
query: {
limit: 8192,
name: 'assets/img/[name]_[hash:7].[ext]'
}
}
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /onepagescroll\.(min)?\.js$/,
use: ['exports-loader?onePageScroll', 'script-loader'],
},
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html'
})
]
};
if (process.env.NODE_ENV === 'production') {
module.exports.module.rules.push({
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer],
},
},
'sass-loader',
],
}),
});
module.exports.output.filename = 'assets/js/[name]_[chunkhash:7].js';
module.exports.plugins.push(new ExtractTextPlugin('assets/css/[name]_[contenthash:7].css'));
} else {
module.exports.module.rules.push({
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer]
}
},
'sass-loader'
]
});
}