123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- const webpack = require('webpack');
- const path = require('path');
- const fileSystem = require('fs-extra');
- const { CleanWebpackPlugin } = require('clean-webpack-plugin');
- const { VueLoaderPlugin } = require('vue-loader');
- const CopyWebpackPlugin = require('copy-webpack-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const TerserPlugin = require('terser-webpack-plugin');
- const env = require('./utils/env');
- const ASSET_PATH = process.env.ASSET_PATH || '/';
- const alias = {};
- // load the secrets
- const secretsPath = path.join(__dirname, 'secrets.' + env.NODE_ENV + '.js');
- const fileExtensions = [
- 'jpg',
- 'jpeg',
- 'png',
- 'gif',
- 'eot',
- 'otf',
- 'svg',
- 'ttf',
- 'woff',
- 'woff2',
- ];
- if (fileSystem.existsSync(secretsPath)) {
- alias['secrets'] = secretsPath;
- }
- const options = {
- mode: process.env.NODE_ENV || 'development',
- entry: {
- newtab: path.join(__dirname, 'src', 'newtab', 'index.js'),
- popup: path.join(__dirname, 'src', 'popup', 'index.js'),
- background: path.join(__dirname, 'src', 'background', 'index.js'),
- contentScript: path.join(__dirname, 'src', 'content', 'index.js'),
- },
- chromeExtensionBoilerplate: {
- notHotReload: ['contentScript', 'devtools'],
- },
- output: {
- path: path.resolve(__dirname, 'build'),
- filename: '[name].bundle.js',
- publicPath: ASSET_PATH,
- },
- module: {
- rules: [
- {
- test: /\.vue$/,
- loader: 'vue-loader'
- },
- {
- // look for .css or .scss files
- test: /\.css$/,
- // in the `src` directory
- use: [
- {
- loader: 'style-loader',
- },
- {
- loader: 'css-loader',
- },
- {
- loader: 'postcss-loader',
- },
- ],
- },
- {
- test: new RegExp('.(' + fileExtensions.join('|') + ')$'),
- loader: 'file-loader',
- options: {
- name: '[name].[ext]',
- },
- exclude: /node_modules/,
- },
- {
- test: /\.js$/,
- use: [
- {
- loader: 'source-map-loader',
- },
- {
- loader: 'babel-loader',
- },
- ],
- exclude: /node_modules/,
- },
- ],
- },
- resolve: {
- alias: alias,
- extensions: fileExtensions
- .map((extension) => '.' + extension)
- .concat(['.js', '.vue', '.css']),
- },
- plugins: [
- new VueLoaderPlugin(),
- new webpack.ProgressPlugin(),
- // clean the build folder
- new CleanWebpackPlugin({
- verbose: true,
- cleanStaleWebpackAssets: true,
- }),
- // expose and write the allowed env vars on the compiled bundle
- new webpack.EnvironmentPlugin(['NODE_ENV']),
- new CopyWebpackPlugin({
- patterns: [
- {
- from: 'src/manifest.json',
- to: path.join(__dirname, 'build'),
- force: true,
- transform: function (content, path) {
- // generates the manifest file using the package.json informations
- return Buffer.from(
- JSON.stringify({
- description: process.env.npm_package_description,
- version: process.env.npm_package_version,
- ...JSON.parse(content.toString()),
- })
- );
- },
- },
- {
- from: 'src/assets/img/icon-128.png',
- to: path.join(__dirname, 'build'),
- force: true,
- },
- {
- from: 'src/assets/img/icon-34.png',
- to: path.join(__dirname, 'build'),
- force: true,
- },
- ],
- }),
- new HtmlWebpackPlugin({
- template: path.join(__dirname, 'src', 'Newtab', 'index.html'),
- filename: 'newtab.html',
- chunks: ['newtab'],
- cache: false,
- }),
- new HtmlWebpackPlugin({
- template: path.join(__dirname, 'src', 'Popup', 'index.html'),
- filename: 'popup.html',
- chunks: ['popup'],
- cache: false,
- }),
- ],
- infrastructureLogging: {
- level: 'info',
- },
- };
- if (env.NODE_ENV === 'development') {
- options.devtool = 'cheap-module-source-map';
- } else {
- options.optimization = {
- minimize: true,
- minimizer: [
- new TerserPlugin({
- extractComments: false,
- }),
- ],
- };
- }
- module.exports = options;
|