forked from ng-select/ng-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.js
111 lines (97 loc) · 3.97 KB
/
webpack.dev.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const path = require('path');
const webpack = require('webpack');
// Webpack Plugins
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
const root = path.join.bind(path, path.resolve(__dirname, '..'));
const ENV = process.env.npm_lifecycle_event;
const isProd = ENV === 'build:demo';
module.exports = function makeWebpackConfig() {
let config = {
devtool: isProd ? 'source-map' : 'eval-source-map',
mode: isProd ? 'production' : 'development',
entry: {
'polyfills': './demo/polyfills.ts',
'app': './demo/main.ts',
},
output: {
path: root('dist'),
publicPath: isProd ? 'ng-select' : 'http://localhost:8080/',
filename: isProd ? 'js/[name].[hash].js' : 'js/[name].js',
chunkFilename: isProd ? '[id].[hash].chunk.js' : '[id].chunk.js'
},
resolve: {
extensions: ['.ts', '.js', '.json', '.css', '.scss', '.html'],
plugins: [
new TsConfigPathsPlugin({
configFileName: './demo/tsconfig.json',
compiler: 'typescript'
})
]
},
module: {
rules: [
{
test: /\.ts$/,
loader: ['awesome-typescript-loader?configFileName=./demo/tsconfig.json', 'angular2-template-loader', 'ng-snippets-loader'],
exclude: [/\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/],
},
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader'
},
// copy those assets to output
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=fonts/[name].[hash].[ext]?'
},
// all scss files in app demo style will be merged to index.html
{
test: /\.scss$/,
include: root('demo', 'style'),
loader: 'style-loader!css-loader!sass-loader'
},
// all themes will be added to bundle as usable
{
test: /(theme)\.scss$/,
loader: 'style-loader/useable!css-loader!sass-loader'
},
// all css required in ng-select files will be merged in js files
{
test: /\.(scss|sass)$/,
exclude: [root('demo', 'style'), root('src', 'themes')],
loader: 'raw-loader!sass-loader'
},
// support for .html as raw text
{ test: /\.html$/, loader: ['raw-loader', 'ng-snippets-loader'], exclude: root('src', 'public') },
// Ignore warnings about System.import in Angular
{ test: /[\/\\]@angular[\/\\].+\.js$/, parser: { system: true } }
]
},
plugins: [
new HtmlWebpackPlugin({
template: './demo/index.ejs',
chunksSortMode: 'dependency',
basePath: isProd ? '/ng-select' : '/',
ngSelectVersion: require(root('./src/package.json')).version
}),
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/(.+)?angular(\\|\/)core(.+)?/,
root('./demo/') // location of your src
),
new CopyWebpackPlugin([{
from: root('./demo/assets'), to: 'assets'
}])
],
devServer: {
contentBase: './demo',
historyApiFallback: true,
quiet: false,
stats: { colors: true }
}
};
return config;
}();