-
Notifications
You must be signed in to change notification settings - Fork 28
/
webpack.config.js
89 lines (87 loc) · 2.24 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
const { resolve } = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MinaWebpackPlugin = require('./plugin/MinaWebpackPlugin')
const MinaRuntimePlugin = require('./plugin/MinaRuntimePlugin')
const LodashWebpackPlugin = require('lodash-webpack-plugin')
const debuggable = process.env.BUILD_TYPE !== 'release'
module.exports = {
context: resolve('src'),
entry: { main: './app.js' },
output: {
path: resolve('dist'),
filename: '[name].js',
publicPath: resolve('dist'),
globalObject: 'wx',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(scss)$/,
include: /src/,
use: [
{
loader: 'file-loader',
options: {
useRelativePath: true,
name: '[path][name].wxss',
context: resolve('src'),
},
},
{
loader: 'sass-loader',
options: {
sassOptions: { includePaths: [resolve('src', 'styles'), resolve('src')] },
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
}),
new CopyWebpackPlugin({
patterns: [
{
from: '**/*',
to: './',
filter: resourcePath => !['.ts', '.js', '.scss'].some(item => resourcePath.endsWith(item)),
},
],
}),
new MinaWebpackPlugin({
scriptExtensions: ['.ts', '.js'],
assetExtensions: ['.scss'],
}),
new MinaRuntimePlugin(),
new LodashWebpackPlugin(),
new webpack.EnvironmentPlugin({
NODE_ENV: JSON.stringify(process.env.NODE_ENV) || 'development',
BUILD_TYPE: JSON.stringify(process.env.BUILD_TYPE) || 'debug',
}),
],
optimization: {
splitChunks: {
chunks: 'all',
name: 'common',
minChunks: 2,
minSize: 0,
},
runtimeChunk: {
name: 'runtime',
},
},
mode: debuggable ? 'none' : 'production',
devtool: debuggable ? 'inline-source-map' : 'source-map',
}