1 |
|
2 |
|
3 |
|
4 | const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin');
|
5 | const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
6 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
7 | const webpack = require('webpack');
|
8 | const { fromCwd } = require('quickenv');
|
9 |
|
10 | const {
|
11 | BUNDLE_NAME,
|
12 | IS_POS,
|
13 | IS_BROWSER,
|
14 | IS_DEV,
|
15 | IS_PROD,
|
16 | NODE_ENV,
|
17 | APP_ENV,
|
18 | ADD_MAMBA_SIMULATOR,
|
19 | } = require('./helpers/consts.js');
|
20 | const {
|
21 | isOfModuleType,
|
22 | transpileIgnoreBaseCondition,
|
23 | } = require('./helpers/depTranspiling.js');
|
24 | const htmlTemplate = require('./helpers/htmlTemplate.js');
|
25 | const loaders = require('./helpers/loaders.js');
|
26 | const MambaFixesPlugin = require('./plugins/MambaFixesPlugin.js');
|
27 |
|
28 |
|
29 | const entry = {
|
30 | app: [
|
31 |
|
32 | '@mamba/styles/dist/pos.css',
|
33 |
|
34 | ADD_MAMBA_SIMULATOR && './simulator.js',
|
35 |
|
36 | './index.js',
|
37 | ].filter(Boolean),
|
38 | };
|
39 |
|
40 | module.exports = {
|
41 | mode: IS_PROD ? 'production' : 'development',
|
42 | cache: true,
|
43 | target: 'web',
|
44 | node: false,
|
45 | context: fromCwd('src'),
|
46 | entry,
|
47 | output: {
|
48 | path: fromCwd('dist', BUNDLE_NAME),
|
49 | publicPath: './',
|
50 | filename: '[name].[hash:5].js',
|
51 | chunkFilename: '[name].[hash:5].js',
|
52 | },
|
53 | resolve: {
|
54 |
|
55 | symlinks: false,
|
56 | enforceExtension: false,
|
57 | mainFields: ['svelte', 'esnext', 'jsnext:main', 'module', 'main'],
|
58 | extensions: ['.js', '.json', '.pcss', '.css', '.html', '.htmlx', '.svelte'],
|
59 |
|
60 | modules: [fromCwd('src'), 'node_modules'],
|
61 | alias: {
|
62 | '@mamba': fromCwd('node_modules', '@mamba'),
|
63 | svelte: fromCwd('node_modules', 'svelte'),
|
64 | page: fromCwd('node_modules', 'page'),
|
65 | },
|
66 | },
|
67 | module: {
|
68 | rules: [
|
69 | |
70 |
|
71 |
|
72 | {
|
73 | test: /\.(htmlx?|svelte)$/,
|
74 | include: [fromCwd('src')],
|
75 | use: [loaders.babelEsNext, loaders.svelte, loaders.eslint],
|
76 | },
|
77 | {
|
78 | test: /\.js$/,
|
79 | include: [fromCwd('src')],
|
80 | use: [loaders.babelEsNext, loaders.eslint],
|
81 | },
|
82 | |
83 |
|
84 |
|
85 |
|
86 | {
|
87 | test: /\.(htmlx?|svelte)$/,
|
88 | include: [/node_modules/],
|
89 |
|
90 | use: [loaders.babelEsNext, loaders.svelte],
|
91 | },
|
92 |
|
93 | {
|
94 | test: /\.mjs$/,
|
95 | include: [/node_modules/],
|
96 | exclude: [/core-js/],
|
97 | use: [loaders.babelEsNext],
|
98 | },
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | {
|
105 | test: {
|
106 | ...transpileIgnoreBaseCondition,
|
107 | and: [isOfModuleType('cjs')],
|
108 | },
|
109 | use: [loaders.babelCJS],
|
110 | },
|
111 |
|
112 | {
|
113 | test: {
|
114 | ...transpileIgnoreBaseCondition,
|
115 | and: [isOfModuleType('es')],
|
116 | },
|
117 | use: [loaders.babelEsNext],
|
118 | },
|
119 | |
120 |
|
121 |
|
122 | {
|
123 | test: /\.(css|pcss)$/,
|
124 | |
125 |
|
126 |
|
127 |
|
128 | resolve: { mainFields: ['style', 'main'] },
|
129 | use: [
|
130 | loaders.extractCss,
|
131 | loaders.css,
|
132 | loaders.postcss,
|
133 | loaders.resolveUrl,
|
134 | ],
|
135 | },
|
136 |
|
137 | { test: /\.(eot|woff2?|otf|ttf)$/, use: [loaders.fonts] },
|
138 |
|
139 | { test: /\.(gif|jpe?g|png|ico|svg)$/, use: [loaders.images] },
|
140 | ],
|
141 | },
|
142 | plugins: [
|
143 |
|
144 | new MambaFixesPlugin(),
|
145 | new ProgressBarPlugin(),
|
146 | new MiniCssExtractPlugin({
|
147 | filename: 'style.css',
|
148 | chunkFilename: '[name].[hash:5].css',
|
149 | }),
|
150 | new MiniHtmlWebpackPlugin({
|
151 | context: { title: 'Mamba Application' },
|
152 | template: htmlTemplate,
|
153 | }),
|
154 | new webpack.DefinePlugin({
|
155 | __NODE_ENV__: JSON.stringify(NODE_ENV),
|
156 | __APP_ENV__: JSON.stringify(APP_ENV),
|
157 | __PROD__: IS_PROD,
|
158 | __TEST__: NODE_ENV === 'test',
|
159 | __DEV__: IS_DEV,
|
160 | __POS__: IS_POS,
|
161 | __SIMULATOR__: ADD_MAMBA_SIMULATOR,
|
162 | __BROWSER__: IS_BROWSER,
|
163 | }),
|
164 | ],
|
165 |
|
166 | stats: {
|
167 | modules: false,
|
168 | chunks: false,
|
169 | colors: true,
|
170 | children: false,
|
171 | },
|
172 | optimization: {
|
173 | namedChunks: true,
|
174 | namedModules: true,
|
175 |
|
176 | runtimeChunk: { name: 'runtime' },
|
177 | splitChunks: {
|
178 | chunks: 'all',
|
179 | minSize: 0,
|
180 | minChunks: 1,
|
181 | cacheGroups: {
|
182 | vendors: false,
|
183 | libs: {
|
184 | test: /[\\/]node_modules[\\/]/,
|
185 | priority: -10,
|
186 | },
|
187 |
|
188 | polyfills: {
|
189 | test: /core-js/,
|
190 | name: 'polyfills',
|
191 | priority: 10,
|
192 | },
|
193 | },
|
194 | },
|
195 | },
|
196 | };
|