-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathwebpack.config.js
92 lines (90 loc) · 2.2 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const path = require('path');
const webpack = require('webpack');
const chalk = require('chalk');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const output = './dist';
module.exports = {
entry: {
'index': './src/page/index/index.js'
},
devtool: 'cheap-module-source-map',
resolve: {
alias: {
asset: path.join(__dirname, 'src/asset'),
},
},
output: {
path: path.join(__dirname, output),
filename: 'js/[name].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader',
],
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
]
}),
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'sass-loader',
]
}),
},
{
test: /\.(png|svg|jpg|jpeg|gif|wav|mp4)$/,
use: {
loader: 'url-loader',
options: {
limit: 2048,
fallback: 'file-loader',
// img output path
name: 'img/[name].[hash:8].[ext]',
},
},
},
],
},
plugins: [
new CleanWebpackPlugin([ output ]),
new webpack.ProgressPlugin((percentage, msg, modules) => {
const stream = process.stderr;
if (stream.isTTY && percentage < 0.71) {
stream.cursorTo(0);
stream.write(chalk.magenta(`📦 ${(modules || '').split(' ')[0]} ${msg} `));
stream.clearLine(1);
}
}),
new HtmlWebpackPlugin({
chunks: [ 'index' ],
filename: 'html/index.html',
template: './src/page/index/index.html',
}),
// css output path
new ExtractTextPlugin('css/[name].css'),
new CopyWebpackPlugin([
'src/background.js',
'src/icon32.png',
'src/icon48.png',
'src/manifest.json',
]),
],
};