Completed
Push — master ( 058858...304cc0 )
by Ajeh
04:20
created

webpack.config.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 1
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 WebpackNotifierPlugin = require('webpack-notifier');
6
const WebpackShellPlugin = require('webpack-shell-plugin');
7
8
const isProduction = process.env.NODE_ENV === 'production'
9
10
const extractSass = new ExtractTextPlugin({
11
    filename: "css/app.[name].css",
12
    disable: false
13
});
14
15
16
const COMMON = {
17
    module: {
18
        rules: [
19
            {
20
                test: /\.vue$/,
21
                use: [{
22
                    loader: 'vue-loader',
23
                    options: {
24
                        loaders: {
25
                            'scss': 'vue-style-loader!css-loader!postcss-loader?sourceMap!sass-loader',
26
                            'sass': 'vue-style-loader!css-loader!postcss-loader?sourceMap!sass-loader?indentedSyntax',
27
                            'css': 'vue-style-loader!css-loader!postcss-loader?sourceMap'
28
                        },
29
                        // other vue-loader options go here
30
                        postcss: [require('postcss-cssnext')()]
31
                    }
32
                }]
33
            },
34
            {
35
                test: /\.js$/,
36
                loader: 'babel-loader',
37
                exclude: /node_modules/
38
            },
39
            {
40
                test: /\.scss$/,
41
                use: extractSass.extract({
42
                    fallback: "style-loader",
43
                    use: [{
44
                        loader: "css-loader",
45
                        options: {minimize: isProduction}
46
                    }, {
47
                        loader: "postcss-loader",
48
                        options: {
49
                            plugins: (loader) => [
0 ignored issues
show
Unused Code introduced by
The parameter loader is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
50
                                require('autoprefixer')()
51
                            ]
52
                        }
53
                    }, {
54
                        loader: "sass-loader"
55
                    }]
56
                })
57
            },
58
            {
59
                test: /\.(png|jpg|gif|svg)$/,
60
                loader: 'file-loader',
61
                options: {
62
                    name: '[name].[ext]?[hash]'
63
                }
64
            }
65
        ]
66
    },
67
    plugins: [
68
        new WebpackNotifierPlugin({alwaysNotify: true}),
69
        new WebpackShellPlugin({
70
            onBuildStart: ['echo "Webpack Start"'],
71
            onBuildEnd: ['echo "Webpack End"'],
72
            onBuildExit: ['node src\\docs\\js\\copy-to-docs.js']
73
        })
74
    ],
75
    watchOptions: {
76
        aggregateTimeout: 300,
77
        ignored: /node_modules/
78
    },
79
    resolve: {
80
        alias: {
81
            'vue$': 'vue/dist/vue.esm.js'
82
        }
83
    },
84
    devServer: {
85
        historyApiFallback: true,
86
        noInfo: true
87
    },
88
    performance: {
89
        hints: false
90
    },
91
    devtool: '#eval-source-map'
92
}
93
94
const DOCS = Object.assign({}, COMMON, {
95
    name: 'docs',
96
    entry: [
97
        './src/docs/js/app.js',
98
        './src/docs/scss/app.scss'
99
    ],
100
    output: {
101
        path: path.resolve(__dirname, './docs'),
102
        filename: "js/app.[name].js",
103
    },
104
    devServer: {
105
        contentBase: path.join(__dirname, "docs"),
106
        compress: true,
107
        port: 9000
108
    },
109
    externals: {
110
        'vue': 'Vue',
111
        'vuejs-dialog': 'VuejsDialog'
112
    },
113
    plugins: [
114
        extractSass,
115
        new HtmlWebpackPlugin({
116
            hash: true,
117
            catch: true,
118
            filename: 'index.html',
119
            template: 'src/docs/index.html'
120
        })
121
    ]
122
})
123
124
const DIST = Object.assign({}, COMMON, {
125
    name: 'dist',
126
    entry: './src/plugin/',
127
    output: {
128
        library: 'VuejsDialog',
129
        libraryTarget: 'umd',
130
        path: path.resolve(__dirname, './dist'),
131
        publicPath: '/dist/',
132
        filename: 'vuejs-dialog.min.js'
133
    }
134
})
135
136
if (isProduction) {
137
    DIST.devtool = '#source-map'
138
    // http://vue-loader.vuejs.org/en/workflow/production.html
139
    DIST.plugins = (DIST.plugins || []).concat([
140
        new webpack.DefinePlugin({
141
            'process.env': {
142
                NODE_ENV: '"production"'
143
            }
144
        }),
145
        new webpack.optimize.UglifyJsPlugin({
146
            sourceMap: true,
147
            compress: {
148
                warnings: false
149
            }
150
        }),
151
        new webpack.LoaderOptionsPlugin({
152
            minimize: true
153
        })
154
    ])
155
156
    DOCS.devtool = '#none'
157
    DOCS.plugins = (DOCS.plugins || []).concat([
158
        new webpack.DefinePlugin({
159
            'process.env': {
160
                NODE_ENV: '"production"'
161
            }
162
        }),
163
        new webpack.optimize.UglifyJsPlugin({
164
            sourceMap: false,
165
            compress: {
166
                warnings: false
167
            }
168
        })
169
    ])
170
}
171
172
module.exports = [DOCS, DIST]