This repository was archived by the owner on Jul 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
109 lines (96 loc) · 2.79 KB
/
Copy pathwebpack.config.js
File metadata and controls
109 lines (96 loc) · 2.79 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
const LIB_DIR = './src/lib';
let OUTPUT_DIR = path.resolve('dist');
const tsConfigPath = path.resolve(__dirname, LIB_DIR, 'tsconfig-build.json');
module.exports = (env) => {
if (!env) {
env = {};
}
if (!env.MODE) {
env.MODE = 'prod';
}
if (!env.ENTRY_ROOT) {
env.ENTRY_ROOT = LIB_DIR;
}
if (!env.ENTRY_EXTENSION) {
env.ENTRY_EXTENSION = 'ts';
}
if (env.OUTPUT_DIR) {
OUTPUT_DIR = env.OUTPUT_DIR;
}
const RELEASE_DIR = path.resolve(OUTPUT_DIR, 'release');
let extension = env.ENTRY_EXTENSION;
const outputPath = path.resolve(__dirname, RELEASE_DIR);
const jsOutputPath = path.resolve(outputPath, 'js');
const config = {
mode: env.MODE ? 'production' : 'development',
entry: {
'lib': `${env.ENTRY_ROOT}/index.${extension}`
},
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, 'node_modules')],
plugins: [
new TsConfigPathsPlugin({
configFileName: tsConfigPath,
})
]
},
output: {
path: jsOutputPath,
filename: 'clean-webpack-plugin-issue-146-[name].js',
library: ['CleanWebpackPluginIssue146', '[name]'],
libraryTarget: 'umd'
},
devtool: 'source-map',
performance: {
hints: false
},
optimization: {
minimize: false,
minimizer: [],
concatenateModules: true,
noEmitOnErrors: true
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: tsConfigPath
}
}
]
},
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.MODE),
}),
// after the build of the TS, we need to copy files to the output folder
new CopyPlugin([
// copy the package.json
{ context: path.resolve(LIB_DIR), from: 'package.json', to: path.resolve(outputPath) },
// copy the html files to the js folder
{ context: path.resolve(LIB_DIR), from: { glob: '**/*.html' }, to: path.resolve(jsOutputPath, 'html') },
// copy the scss files to the sass folder
{ context: path.resolve(LIB_DIR), from: { glob: '**/*.scss' }, to: path.resolve(outputPath, 'sass') },
]),
]
};
if (!env.SKIP_CLEAN) {
config.plugins.push(new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: [OUTPUT_DIR], verbose: false }));
}
if (env.ENTRY) {
config.entry = env.ENTRY;
}
return config;
};