Gitako/webpack.config.js
2019-11-18 19:49:58 +08:00

84 lines
2.2 KiB
JavaScript

const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const path = require('path')
const Dotenv = require('dotenv-webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const srcPath = path.resolve(__dirname, 'src')
const packagesPath = path.resolve(__dirname, 'packages')
const plugins = [
new CopyWebpackPlugin([
{
from: './src/manifest.json',
to: 'manifest.json',
},
{
from: './src/assets/icons/*',
to: 'icons/[name].[ext]',
},
]),
new ForkTsCheckerWebpackPlugin(),
new Dotenv(),
]
const analyse = process.env.ANALYSE !== undefined
if (analyse) {
plugins.push(new BundleAnalyzerPlugin())
console.log(`BundleAnalyzerPlugin added`)
}
const IN_PRODUCTION_MODE = process.env.NODE_ENV === 'production'
plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.VERSION': JSON.stringify(process.env.VERSION),
}),
)
module.exports = {
entry: {
content: './src/content.tsx',
'browser-polyfill': './node_modules/webextension-polyfill/dist/browser-polyfill.js',
'firefox-shim': './src/firefox-shim.js',
},
devtool: IN_PRODUCTION_MODE ? 'source-map' : 'eval-source-map',
mode: IN_PRODUCTION_MODE ? 'production' : 'development',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
modules: [srcPath, packagesPath, 'node_modules'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
include: [srcPath, packagesPath],
},
{
test: /\.less$/,
loader: ['style-loader', 'css-loader', 'less-loader'],
include: [srcPath],
},
{
test: /\.svg$/,
resourceQuery: /inline/,
loader: ['url-loader'],
},
{
test: /\.json$/,
loader: ['json-loader'],
include: [srcPath],
},
],
},
plugins,
}