1+ const path = require ( 'path' ) ;
2+ const MahalPlugin = require ( 'mahal-webpack-loader/lib/plugin' ) ;
3+ const HtmlWebPackPlugin = require ( 'html-webpack-plugin' ) ;
4+ const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' ) ;
5+ const CopyPlugin = require ( 'copy-webpack-plugin' ) ;
6+ const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
7+ const webpack = require ( 'webpack' ) ;
8+
9+ const rootFolder = path . join ( __dirname , '../../' ) ;
10+
11+ const isEnvProduction = process . env . NODE_ENV === "production"
12+
13+ module . exports = {
14+ entry : './src/index.js' ,
15+ devtool : 'source-map' ,
16+ mode : process . env . NODE_ENV || "development" ,
17+ module : {
18+ rules : [
19+ {
20+ test : / \. m a h a l ? $ / ,
21+ // loader: 'mahal-webpack-loader',
22+ use : {
23+ loader : require . resolve ( 'mahal-webpack-loader' )
24+ } ,
25+ exclude : / n o d e _ m o d u l e s /
26+ } ,
27+ {
28+ test : / \. j s | .j s x ? $ / ,
29+ exclude : / ( n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s ) / ,
30+ use : {
31+ loader : 'babel-loader'
32+ }
33+ } ,
34+ {
35+ test : / \. c s s ? $ / ,
36+ use : [
37+ {
38+ loader : MiniCssExtractPlugin . loader ,
39+ options : {
40+ esModule : false ,
41+ } ,
42+ } ,
43+ 'css-loader'
44+ ] ,
45+ } ,
46+ {
47+ test : / \. s [ a c ] s s $ / i,
48+ use : [
49+ // Creates `style` nodes from JS strings
50+ // "style-loader",
51+ {
52+ loader : MiniCssExtractPlugin . loader ,
53+ options : {
54+ esModule : false ,
55+ } ,
56+ } ,
57+ // Translates CSS into CommonJS
58+ "css-loader" ,
59+ // Compiles Sass to CSS
60+ "sass-loader" ,
61+ ] ,
62+ } ,
63+ // Images
64+ {
65+ test : / \. (?: i c o | g i f | p n g | j p g | j p e g ) $ / i,
66+ type : 'asset/resource' ,
67+ } ,
68+ // Fonts and SVGs
69+ {
70+ test : / \. ( w o f f ( 2 ) ? | e o t | t t f | o t f | s v g | ) $ / ,
71+ type : 'asset/inline' ,
72+ } ,
73+ ]
74+ } ,
75+ resolve : {
76+ extensions : [ '.ts' , '.js' , '.css' , '.mahal' , '.scss' ] ,
77+ alias : {
78+ "~" : rootFolder ,
79+ "@" : path . join ( rootFolder , 'src' ) ,
80+ "@config" : path . join ( rootFolder , 'config' ) ,
81+ "@components" : path . join ( rootFolder , 'src' , 'components' ) ,
82+ process : "process/browser"
83+ } ,
84+ } ,
85+ output : {
86+ filename : isEnvProduction ? 'js/[name].[contenthash:8].js' : 'js/[name].js' ,
87+ chunkFilename : isEnvProduction ? 'js/[name].[contenthash:8].chunk.js' : 'js/[name].chunk.js' ,
88+ path : path . resolve ( rootFolder , 'dist' ) ,
89+ publicPath : '/'
90+ } ,
91+ plugins : [
92+ new MahalPlugin ( {
93+ lang : 'js'
94+ } ) ,
95+ new HtmlWebPackPlugin ( {
96+ cache : true ,
97+ hash : true ,
98+ template : 'src/index.html' ,
99+ minify : {
100+ collapseWhitespace : true ,
101+ removeComments : true ,
102+ removeRedundantAttributes : true ,
103+ removeScriptTypeAttributes : true ,
104+ removeStyleLinkTypeAttributes : true
105+ }
106+ } ) ,
107+ new CleanWebpackPlugin ( ) ,
108+ new CopyPlugin ( {
109+ patterns : [ {
110+ from : './assets/' ,
111+ to : ''
112+ } ]
113+ } ) ,
114+ new MiniCssExtractPlugin ( {
115+ filename : isEnvProduction ? 'css/[name].[contenthash:8].css' : 'css/[name].css' ,
116+ chunkFilename : isEnvProduction ? 'css/[name].[contenthash:8].chunk.css' : 'css/[name].chunk.css' ,
117+ } ) ,
118+
119+ ]
120+ } ;
0 commit comments