-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (106 loc) · 2.73 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
const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const WebpackAssetsManifest = require('webpack-assets-manifest')
const webpackConfig = {
isDevelopment: process.env.NODE_ENV !== 'production',
stylesheets: {
components: path.resolve(__dirname, 'src', 'server', 'common', 'components')
}
}
const ASSETS_RESOURCE_PATH = 'asset/resource'
module.exports = {
entry: {
application: './src/client/assets/javascripts/application.js'
},
mode: webpackConfig.isDevelopment ? 'development' : 'production',
...(webpackConfig.isDevelopment && { devtool: 'source-map' }),
watchOptions: {
aggregateTimeout: 200,
poll: 1000
},
output: {
filename: 'js/[name].[fullhash].js',
path: path.resolve(__dirname, '.public'),
library: '[name]'
},
module: {
rules: [
...(webpackConfig.isDevelopment
? [
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader']
}
]
: []),
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { targets: 'defaults' }]]
}
}
},
{
test: /\.(?:s[ac]|c)ss$/i,
use: [
'style-loader',
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../',
esModule: false
}
},
'css-loader',
...(webpackConfig.isDevelopment ? ['resolve-url-loader'] : []),
{
loader: 'sass-loader',
options: {
...(webpackConfig.isDevelopment && { sourceMap: true }),
sassOptions: {
outputStyle: 'compressed',
quietDeps: true,
includePaths: [webpackConfig.stylesheets.components]
}
}
}
]
},
{
test: /\.(png|svg|jpe?g|gif)$/,
type: ASSETS_RESOURCE_PATH,
generator: {
filename: 'images/[name].[contenthash][ext]'
}
},
{
test: /\.(ico)$/,
type: ASSETS_RESOURCE_PATH,
generator: {
filename: 'images/[name][ext]'
}
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
type: ASSETS_RESOURCE_PATH,
generator: {
filename: 'fonts/[name].[contenthash][ext]'
}
}
]
},
plugins: [
new CleanWebpackPlugin(),
new WebpackAssetsManifest({
output: 'manifest.json'
}),
new MiniCssExtractPlugin({
filename: 'css/[name].[fullhash].css'
})
]
}