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