formatting webpack js file

This commit is contained in:
Kyle Spearrin 2018-04-07 00:24:37 -04:00
parent 09f770c7b0
commit 4baef72144
1 changed files with 32 additions and 33 deletions

View File

@ -10,19 +10,16 @@ const isVendorModule = (module) => {
if (!module.context) {
return false;
}
const nodeModule = module.context.indexOf('node_modules') !== -1;
const bitwardenModule = module.context.indexOf('@bitwarden') !== -1;
return nodeModule && !bitwardenModule;
return module.context.indexOf('node_modules') !== -1;
};
const extractCss = new ExtractTextPlugin({
filename: '[name].css',
disable: false,
allChunks: true
allChunks: true,
});
module.exports = {
const config = {
entry: {
'popup/main': './src/popup2/main.ts',
'background': './src/background.ts',
@ -39,26 +36,26 @@ module.exports = {
jslib: path.join(__dirname, 'jslib/src'),
},
symlinks: false,
modules: [path.resolve('node_modules')]
modules: [path.resolve('node_modules')],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build2')
path: path.resolve(__dirname, 'build2'),
},
module: {
rules: [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader'
loader: 'tslint-loader',
},
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '@ngtools/webpack'
loader: '@ngtools/webpack',
},
{
test: /\.(html)$/,
loader: 'html-loader'
loader: 'html-loader',
},
{
test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
@ -68,9 +65,9 @@ module.exports = {
options: {
name: '[name].[ext]',
outputPath: 'popup/fonts/',
publicPath: './fonts/'
}
}]
publicPath: './fonts/',
},
}],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
@ -80,9 +77,9 @@ module.exports = {
options: {
name: '[name].[ext]',
outputPath: 'popup/images/',
publicPath: './images/'
}
}]
publicPath: './images/',
},
}],
},
{
test: /\.scss$/,
@ -93,56 +90,56 @@ module.exports = {
},
{
loader: 'sass-loader',
}
},
],
publicPath: '../'
})
publicPath: '../',
}),
},
]
],
},
plugins: [
new CleanWebpackPlugin([
path.resolve(__dirname, 'build2/*')
path.resolve(__dirname, 'build2/*'),
]),
new AngularCompilerPlugin({
tsConfigPath: 'tsconfig.json',
entryModule: 'src/popup2/app.module#AppModule',
sourceMap: true
sourceMap: true,
}),
// ref: https://github.com/angular/angular/issues/20357
new webpack.ContextReplacementPlugin(
/\@angular(\\|\/)core(\\|\/)esm5/,
path.resolve(__dirname, './src')
path.resolve(__dirname, './src'),
),
new webpack.optimize.CommonsChunkPlugin({
name: 'popup/vendor',
chunks: ['popup/main'],
minChunks: isVendorModule
minChunks: isVendorModule,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['background'],
minChunks: isVendorModule
minChunks: isVendorModule,
}),
new HtmlWebpackPlugin({
template: './src/popup2/index.html',
filename: 'popup/index.html',
chunks: ['popup/vendor', 'popup/main']
chunks: ['popup/vendor', 'popup/main'],
}),
new HtmlWebpackPlugin({
template: './src/background.html',
filename: 'background.html',
chunks: ['vendor', 'background']
chunks: ['vendor', 'background'],
}),
new HtmlWebpackPlugin({
template: './src/downloader/index.html',
filename: 'downloader/index.html',
chunks: ['downloader/downloader']
chunks: ['downloader/downloader'],
}),
new HtmlWebpackPlugin({
template: './src/2fa/index.html',
filename: '2fa/index.html',
chunks: ['2fa/2fa']
chunks: ['2fa/2fa'],
}),
new CopyWebpackPlugin([
'./src/manifest.json',
@ -150,12 +147,14 @@ module.exports = {
{ from: './src/edge', to: 'edge' },
{ from: './src/safari', to: 'safari' },
{ from: './src/images', to: 'images' },
{ from: './src/content/autofill.css', to: 'content' }
{ from: './src/content/autofill.css', to: 'content' },
]),
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
include: ['popup/main.js', 'background.js']
include: ['popup/main.js', 'background.js'],
}),
extractCss
extractCss,
],
};
module.exports = config;