106 lines
2.4 KiB
JavaScript
106 lines
2.4 KiB
JavaScript
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
import CspHtmlWebpackPlugin from 'csp-html-webpack-plugin';
|
|
import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin';
|
|
|
|
import path from 'path';
|
|
|
|
const sourceDirectory = path.resolve(__dirname, 'src');
|
|
|
|
export default (env, { mode }) => {
|
|
const development = mode === 'development';
|
|
const production = !development;
|
|
|
|
return ({
|
|
optimization: {
|
|
runtimeChunk: {
|
|
name: 'wp',
|
|
},
|
|
},
|
|
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
template: './src/index.html',
|
|
inject: 'head',
|
|
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no',
|
|
minify: production,
|
|
xhtml: true,
|
|
}),
|
|
production && new CspHtmlWebpackPlugin({
|
|
'base-uri': "'self'",
|
|
'object-src': "'none'",
|
|
'script-src': ["'self'", 'nonce-uGo4I9ydb2hP393boc/24Vu7diUk/Mf84w9khcZkynk='],
|
|
'style-src': ["'self'"],
|
|
}),
|
|
production && new ScriptExtHtmlWebpackPlugin({
|
|
defaultAttribute: 'defer',
|
|
custom: [
|
|
{
|
|
test: /./,
|
|
attribute: 'nonce',
|
|
value: 'uGo4I9ydb2hP393boc/24Vu7diUk/Mf84w9khcZkynk=',
|
|
},
|
|
],
|
|
}),
|
|
].filter(v => v),
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/i,
|
|
include: sourceDirectory,
|
|
use: [
|
|
{
|
|
loader: 'babel-loader',
|
|
options: {
|
|
presets: [
|
|
['@babel/env', {
|
|
targets: {
|
|
},
|
|
}],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
|
|
{
|
|
test: /\.css$/i,
|
|
use: [
|
|
'style-loader',
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
modules: true,
|
|
camelCase: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
|
|
|
|
{
|
|
test: /\.styl$/i,
|
|
use: [
|
|
'style-loader',
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
modules: true,
|
|
camelCase: true,
|
|
importLoaders: 2,
|
|
},
|
|
},
|
|
'resolve-url-loader',
|
|
{
|
|
loader: 'stylus-loader',
|
|
options: {
|
|
sourceMap: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
};
|