-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
91 lines (89 loc) · 3.17 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const artifact = require('./package.json');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const fileName = `${artifact.name}-${artifact.version.slice(0, 3)}`;
module.exports = (env, argv) => ({
entry: {
[fileName]: './src/index.js',
},
output: {
filename: '[name].[hash].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
devServer: {
historyApiFallback: true,
static: {
directory: path.resolve(__dirname, '../dist'),
},
open: true,
compress: true,
hot: true,
port: 8080,
},
module: {
rules: [
{
test: /\.(scss|css)$/,
use: [
argv.mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{ loader: 'css-loader', options: { sourceMap: true, importLoaders: 1 } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } },
],
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: ['babel-loader', 'eslint-loader']
},
{
test: /\.(?:ico|gif|png|jpg|jpeg|webp|svg|stl)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
context: 'src', // prevent display of src/ in filename
},
},
{
test: /\.(woff(2)?|eot|ttf|otf|)$/,
loader: 'url-loader',
options: {
limit: 8192,
name: '[path][name].[ext]',
context: 'src', // prevent display of src/ in filename
},
},
],
},
plugins: [
...(argv.mode === 'production' ? [new CleanWebpackPlugin({ verbose: true })] : []),
new webpack.HotModuleReplacementPlugin(),
new CopyWebpackPlugin({
patterns: [{ from: path.resolve(__dirname, 'public'), to: 'assets' }],
}),
new MiniCssExtractPlugin({
filename: 'styles/[name].[hash].css',
chunkFilename: '[id].css',
}),
new HtmlWebpackPlugin({
title: 'Three.js',
//favicon: path.resolve(__dirname, 'public/favicon.png'),
template: path.resolve(__dirname, 'src/index.html'), // template file
filename: 'index.html', // output file
}),
// @ts-ignore
new StylelintPlugin({ configFile: './.stylelintrc', context: 'src', files: '**/*.scss' }),
],
devtool: argv.mode === 'production' ? 'none' : 'eval-source-map',
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
});