1 | const path = require( 'path' );
|
2 | const webpack = require( 'webpack' );
|
3 | const HtmlWebpackPlugin = require( 'html-webpack-plugin' );
|
4 | const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
|
5 | const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
6 | const GenerateJsonPlugin = require( 'generate-json-webpack-plugin' );
|
7 | const MinifyPlugin = require( 'babel-minify-webpack-plugin' );
|
8 |
|
9 | const srcDir = path.resolve( __dirname, '..', 'src' );
|
10 | const distDir = path.resolve( __dirname, '..', 'dist' );
|
11 |
|
12 | module.exports = {
|
13 | mode: 'production',
|
14 |
|
15 | context: srcDir,
|
16 |
|
17 | devtool: false,
|
18 |
|
19 | entry: {
|
20 | application: './app/index.js',
|
21 | components: srcDir + '/components/components.scss'
|
22 | },
|
23 |
|
24 | output: {
|
25 | filename: '[name].[hash].min.js',
|
26 | path: distDir,
|
27 | publicPath: '/',
|
28 | sourceMapFilename: '[name].[hash].map'
|
29 | },
|
30 |
|
31 | module: {
|
32 | rules: [
|
33 | {
|
34 | test: /\.ejs$/,
|
35 | loader: 'ejs-loader'
|
36 | },
|
37 | {
|
38 | test: /\.html$/,
|
39 | use: [
|
40 | {
|
41 | loader: 'html-loader',
|
42 | options: {
|
43 | minimize: true
|
44 | }
|
45 | }
|
46 | ]
|
47 | },
|
48 | {
|
49 | test: /\.js$/,
|
50 | exclude: /node_modules/,
|
51 | use: [ 'babel-loader' ]
|
52 | },
|
53 | {
|
54 | test: /\.js$/,
|
55 | exclude: /node_modules/,
|
56 | enforce: 'pre',
|
57 |
|
58 | loader: 'eslint-loader',
|
59 | options: {
|
60 | emitWarning: true
|
61 | }
|
62 | },
|
63 | {
|
64 | test: /\.(scss|css)$/,
|
65 | use: ExtractTextPlugin.extract( {
|
66 | fallback: 'style-loader',
|
67 | use: [
|
68 | {
|
69 | loader: 'css-loader',
|
70 | options: {
|
71 | minimize: true
|
72 | }
|
73 | },
|
74 | {
|
75 | loader: 'sass-loader'
|
76 | },
|
77 | {
|
78 | loader: 'postcss-loader',
|
79 | options: {
|
80 | plugins: loader => [ require( 'autoprefixer' ) ]
|
81 | }
|
82 | }
|
83 | ]
|
84 | } )
|
85 | },
|
86 | {
|
87 | test: /\.svg$/,
|
88 | loader: 'svg-inline-loader'
|
89 | },
|
90 | {
|
91 | test: /\.(jpg|jpeg|png|gif|ico)$/,
|
92 | loader: 'url-loader',
|
93 | query: {
|
94 | limit: 10000,
|
95 | name: 'static/[name].[hash].[ext]'
|
96 | }
|
97 | }
|
98 | ]
|
99 | },
|
100 |
|
101 | plugins: [
|
102 | new CopyWebpackPlugin( [
|
103 | {
|
104 | from: './../static',
|
105 | to: ''
|
106 | }
|
107 | ] ),
|
108 |
|
109 | new MinifyPlugin(),
|
110 |
|
111 | new webpack.NamedModulesPlugin(),
|
112 |
|
113 | new HtmlWebpackPlugin( {
|
114 | template: path.join( srcDir, 'app/index.ejs' ),
|
115 | path: distDir,
|
116 | filename: 'index.html',
|
117 | minify: {
|
118 | removeComments: true,
|
119 | minifyJS: true,
|
120 | minifyCSS: true,
|
121 | collapseWhitespace: true
|
122 | }
|
123 | } ),
|
124 |
|
125 | new ExtractTextPlugin( 'css/[name].css' ),
|
126 | new ExtractTextPlugin( 'css/[name].min.css' )
|
127 | ]
|
128 | };
|