This repository was archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
48 lines (46 loc) · 1.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
const glob = require("glob");
const mode = process.env.NODE_ENV === 'development' ? 'development' : 'production';
const path = require("path");
const webpack = require("webpack");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
module.exports = {
entry: glob.sync("./app/javascript/packs/**/*.{js,jsx,scss}")
.reduce((entries, pack) => Object.assign(entries, { [pack.substr(23).replace(/\.js(x)?$/, '')]: pack }), {}),
mode,
module: {
rules: [
// transpile js using Babel
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
// compile css from scss, but leave asset url substitution to sprockets
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { url: false }, }, 'sass-loader'],
},
// emit images from app/javascript to assets
{
loader: 'file-loader',
options: {
name(resourcePath, _resourceQuery) {
return resourcePath.replace(/^.*app\/javascript\/images\//, '');
},
},
test: /\.(png|jpe?g|gif|eot|ico|otf|webp|woff2|woff|ttf|tiff|svg)$/i,
},
],
},
optimization: { moduleIds: 'deterministic' },
output: {
path: path.resolve(__dirname, "app/assets/builds"),
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new FixStyleOnlyEntriesPlugin(),
new MiniCssExtractPlugin(),
],
resolve: { extensions: ['.js', '.jsx', '.scss', '.css'], },
}