ghost-keychain/packages/extension/webpack.config.js

111 lines
2.7 KiB
JavaScript

// Copyright 2019 @polkadot/extension authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-extension-manifest-plugin');
const pkgJson = require('./package.json');
const manifest = require('./manifest.json');
const packages = [
'extension',
'extension-ui'
];
function createWebpack ({ alias = {}, context }) {
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
return {
context,
devtool: false,
entry: {
background: './src/background/index.ts',
content: './src/content.ts',
page: './src/page/index.ts',
popup: `./src/popup.ts`
},
mode: ENV,
output: {
chunkFilename: `[name].js`,
filename: `[name].js`,
globalObject: `(typeof self !== 'undefined' ? self : this)`,
path: path.join(context, 'build')
},
resolve: {
alias,
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
exclude: /(node_modules)/,
use: [
require.resolve('thread-loader'),
{
loader: require.resolve('babel-loader'),
options: require('@polkadot/dev-react/config/babel')
}
]
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
use: [
{
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/[name].[ext]'
}
}
]
}
]
},
node: {
child_process: 'empty',
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty'
},
performance: {
hints: false
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(ENV),
PKG_NAME: JSON.stringify(pkgJson.name),
PKG_VERSION: JSON.stringify(pkgJson.version),
}
}),
new CopyPlugin([{ from: 'public' }]),
new ManifestPlugin({
config: {
base: manifest,
extend: {
version: pkgJson.version.split('-')[0] // remove possible -beta.xx
}
}
})
].filter((entry) => entry),
watch: !isProd
};
}
module.exports = createWebpack({
context: __dirname,
alias: packages.reduce((alias, pkg) => {
alias[`@polkadot/${pkg}`] = path.resolve(__dirname, `../${pkg}/src`);
return alias;
}, {})
});