2018-12-30 23:16:09 +01:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const ejs = require('ejs');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const WebpackShellPlugin = require('webpack-shell-plugin');
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader');
|
|
|
|
const { VueLoaderPlugin } = require('vue-loader');
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
mode: process.env.NODE_ENV,
|
2019-05-07 23:03:13 +02:00
|
|
|
devtool: "inline-source-map",
|
2018-12-30 23:16:09 +01:00
|
|
|
context: __dirname + '/src',
|
|
|
|
entry: {
|
2018-12-30 23:41:44 +01:00
|
|
|
'ext/uw': './ext/uw.js',
|
2018-12-30 23:16:09 +01:00
|
|
|
'ext/uw-bg': './ext/uw-bg.js',
|
|
|
|
'popup/popup': './popup/popup.js',
|
|
|
|
'options/options': './options/options.js',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: __dirname + '/dist',
|
|
|
|
filename: '[name].js',
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.vue'],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loaders: 'vue-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.sass$/,
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader?indentedSyntax'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif|svg|ico)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[path][name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff(2)?)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[path][name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new VueLoaderPlugin(),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: '[name].css',
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{ from: 'res', to: 'res'},
|
|
|
|
{ from: 'ext', to: 'ext'},
|
|
|
|
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
|
|
|
|
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
|
|
|
|
{ from: 'options/options.html', to: 'options/options.html', transform: transformHtml },
|
|
|
|
{
|
|
|
|
from: 'manifest.json',
|
|
|
|
to: 'manifest.json',
|
|
|
|
transform: (content) => {
|
|
|
|
const jsonContent = JSON.parse(content);
|
2019-05-04 17:05:08 +02:00
|
|
|
// jsonContent.version = version;
|
2018-12-30 23:16:09 +01:00
|
|
|
|
|
|
|
if (config.mode === 'development') {
|
|
|
|
jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
|
|
|
|
}
|
|
|
|
|
2019-11-28 23:37:26 +01:00
|
|
|
if (process.env.CHANNEL === 'nightly') {
|
|
|
|
jsonContent.name = "Ultrawidify - nightly";
|
2019-11-29 00:12:31 +01:00
|
|
|
jsonContent.description = "FOR TESTING ONLY -- THIS BUILD USES ONLY THE FRESHEST COMMITS FROM GITHUB AND MAY THEREFORE BE COMPLETELY BROKEN";
|
2019-11-28 23:37:26 +01:00
|
|
|
|
|
|
|
// version numbers for nightly builds: YYMM.DD.BUILD_NUMBER
|
|
|
|
jsonContent.version = `${new Date()
|
|
|
|
.toISOString() // YYYY-MM-DDTHH:MM:SS...
|
|
|
|
.split('T')[0] // gives YYYY-MM-DD
|
|
|
|
.substr(2) // YYYY -> YY
|
|
|
|
.replace('-', '') // YY-MM-DD -> YYMM-DD
|
|
|
|
.replace('-', '.') // YYMM-DD -> YYMM.DD
|
|
|
|
}.${process.env.BUILD_NUMBER}`;
|
|
|
|
jsonContent.browser_action.default_title = "Ultrawidify Nightly";
|
2019-11-29 00:31:20 +01:00
|
|
|
|
|
|
|
// otherwise things will get fun!
|
|
|
|
delete jsonContent.applications;
|
2019-11-28 23:37:26 +01:00
|
|
|
}
|
|
|
|
|
2019-05-09 21:10:45 +02:00
|
|
|
if (process.env.BROWSER !== 'firefox') {
|
|
|
|
jsonContent.version = jsonContent.version.replace(/[a-zA-Z-]/g, '');
|
|
|
|
}
|
|
|
|
|
2018-12-30 23:16:09 +01:00
|
|
|
return JSON.stringify(jsonContent, null, 2);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
new WebpackShellPlugin({
|
|
|
|
onBuildEnd: ['node scripts/remove-evals.js'],
|
|
|
|
}),
|
2019-05-09 21:10:45 +02:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.BROWSER': JSON.stringify(process.env.BROWSER)
|
|
|
|
})
|
2018-12-30 23:16:09 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (config.mode === 'production') {
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: '"production"',
|
|
|
|
},
|
2019-05-09 21:10:45 +02:00
|
|
|
})
|
2018-12-30 23:16:09 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.HMR === 'true') {
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
|
|
|
new ChromeExtensionReloader(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function transformHtml(content) {
|
|
|
|
return ejs.render(content.toString(), {
|
|
|
|
...process.env,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config;
|