UNPKG

2.32 kBJavaScriptView Raw
1const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2const { IS_WATCHING } = require('quickenv');
3/** Read the template's .babelrc.js to enforce it in 'babel-loader' */
4const babelrc = require('@mamba/configs/babel/template.js');
5const { extendPresetEnv } = require('@mamba/configs/babel/utils.js');
6/** Read the svelte config file from the project */
7const svelteConfig = require('@mamba/configs/svelte/index.js');
8
9const { IS_DEV } = require('./consts.js');
10
11const babelLoaderConfig = {
12 loader: 'babel-loader',
13 options: {
14 sourceMaps: IS_DEV,
15 cacheDirectory: IS_DEV,
16 babelrc: false,
17 ...babelrc,
18 },
19};
20
21module.exports = {
22 babelEsNext: babelLoaderConfig,
23 babelCJS: {
24 ...babelLoaderConfig,
25 options: extendPresetEnv(babelLoaderConfig.options, {
26 modules: 'commonjs',
27 }),
28 },
29 eslint: {
30 loader: 'eslint-loader',
31 options: { emitWarning: IS_DEV },
32 },
33 /**
34 * MiniCssExtractPlugin doesn't support HMR.
35 * For developing, use 'style-loader' instead.
36 * */
37 extractCss: IS_WATCHING() ? 'style-loader' : MiniCssExtractPlugin.loader,
38 css: {
39 loader: 'css-loader',
40 options: {
41 sourceMap: IS_DEV,
42 /** Apply the two last loaders (resolve-url, postcss) to @imported url() css files */
43 importLoaders: 2,
44 },
45 },
46 /** Use postcss loader in case of extraneous css files */
47 postcss: {
48 loader: 'postcss-loader',
49 options: {
50 sourceMap: true, // 'resolve-url-loader' requires this to be always true
51 },
52 },
53 resolveUrl: {
54 loader: 'resolve-url-loader',
55 options: {
56 sourceMap: IS_DEV,
57 keepQuery: true,
58 debug: false, // IS_DEV,
59 },
60 },
61 fonts: {
62 loader: 'url-loader',
63 options: {
64 fallback: 'file-loader',
65 limit: 1, // Copy font files instead of inserting them on the css
66 outputPath: 'assets/',
67 name: './fonts/[name].[ext]',
68 },
69 },
70 images: {
71 loader: 'url-loader',
72 options: {
73 fallback: 'file-loader',
74 limit: 1,
75 outputPath: 'assets/',
76 name: './images/[name].[hash:5].[ext]',
77 },
78 },
79 svelte: {
80 loader: 'svelte-loader',
81 options: {
82 emitCss: true,
83 hotReload: IS_DEV,
84 /** fix for svelte-loader not setting css: false when emitCss: true */
85 css: false,
86 ...svelteConfig,
87 },
88 },
89};