Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify directory structure #15

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"watch": "webpack --watch --env target=firefox",
"start": "concurrently \"npm:watch\" \"npm:web-ext:run:firefox\"",
"start:noreload": "npm run web-ext:run:firefox -- --no-reload",
"web-ext:run:firefox": "web-ext -s build/extension/firefox run --target firefox-desktop",
"web-ext:run:chrome": "web-ext -s build/extension/chrome run --target chromium --arg='--disable-search-engine-choice-screen'",
"web-ext:run:firefox": "web-ext -s build/firefox run --target firefox-desktop",
"web-ext:run:chrome": "web-ext -s build/chrome run --target chromium --arg='--disable-search-engine-choice-screen'",
"lint": "npm run lint:js && npm run lint:style",
"lint:js": "wp-scripts lint-js",
"lint:style": "wp-scripts lint-style",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/extension/sidebar/sidebar.html → src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Try WordPress</title>
<link rel="stylesheet" type="text/css" href="sidebar.css">
<link rel="stylesheet" type="text/css" href="app.css">
</head>
<body>
<div id="content">
Expand All @@ -15,6 +15,6 @@
</div>
<iframe id="playground"></iframe>
</div>
<script src="index.js" type="module"></script>
<script src="app.js" type="module"></script>
</body>
</html>
File renamed without changes.
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
},
"content_scripts": [
{
"js": [ "content/index.js" ],
"js": [ "content.js" ],
"matches": [ "<all_urls>" ]
}
],
"background": {
"service_worker": "background/index.js"
"service_worker": "background.js"
},
"side_panel": {
"default_title": "Try WordPress",
"default_icon": {
"32": "icons/icon-32.png",
"128": "icons/icon-128"
},
"default_path": "sidebar/sidebar.html"
"default_path": "app.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
},
"content_scripts": [
{
"js": [ "content/index.js" ],
"js": [ "content.js" ],
"matches": [ "<all_urls>" ]
}
],
"background": {
"scripts": [ "background/index.js" ]
"scripts": [ "background.js" ]
},
"sidebar_action": {
"default_title": "Try WordPress",
"default_icon": {
"32": "icons/icon-32.png",
"128": "icons/icon-128"
},
"default_panel": "sidebar/sidebar.html",
"default_panel": "app.html",
"open_at_install": true
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 16 additions & 29 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function ( env ) {

// Build the extension.
function extensionModules( mode, target ) {
const targetPath = path.resolve( __dirname, 'build', 'extension', target );
const targetPath = path.resolve( __dirname, 'build', target );
const resolve = { extensions: [ '.ts', '.tsx', '.js' ] };
const module = {
rules: [
Expand All @@ -40,20 +40,20 @@ function extensionModules( mode, target ) {
mode,
resolve,
module,
entry: './src/extension/background/index.ts',
entry: './src/background.ts',
output: {
path: targetPath,
filename: path.join( 'background', 'index.js' ),
filename: path.join( 'background.js' ),
},
plugins: [
new CopyPlugin( {
patterns: [
{
from: `./src/extension/manifest-${ target }.json`,
from: `./src/assets/manifest-${ target }.json`,
to: path.join( targetPath, 'manifest.json' ),
},
{
from: './src/extension/icons',
from: './src/assets/icons',
to: path.join( targetPath, 'icons' ),
},
],
Expand All @@ -65,40 +65,32 @@ function extensionModules( mode, target ) {
mode,
resolve,
module,
entry: './src/extension/content/index.ts',
entry: './src/content.ts',
output: {
path: targetPath,
filename: path.join( 'content', 'index.js' ),
filename: path.join( 'content.js' ),
},
},
// Extension sidebar.
{
mode,
resolve,
module,
entry: './src/extension/sidebar/index.ts',
entry: './src/app.ts',
output: {
path: targetPath,
filename: path.join( 'sidebar', 'index.js' ),
filename: path.join( 'app.js' ),
},
plugins: [
new CopyPlugin( {
patterns: [
{
from: './src/extension/sidebar/sidebar.html',
to: path.join(
targetPath,
'sidebar',
'sidebar.html'
),
from: './src/app.html',
to: path.join( targetPath, 'app.html' ),
},
{
from: './src/extension/sidebar/sidebar.css',
to: path.join(
targetPath,
'sidebar',
'sidebar.css'
),
from: './src/app.css',
to: path.join( targetPath, 'app.css' ),
},
],
} ),
Expand All @@ -112,15 +104,15 @@ function extensionModules( mode, target ) {
entry: './src/plugin/scripts/index.ts',
output: {
path: targetPath,
filename: path.join( 'sidebar', 'plugin', 'index.js' ),
filename: path.join( 'plugin', 'index.js' ),
},
plugins: [
new CopyPlugin( {
patterns: [
{
from: '**/*',
context: 'src/plugin/',
to: path.join( targetPath, 'sidebar', 'plugin' ),
to: path.join( targetPath, 'plugin' ),
globOptions: {
ignore: [ '**/scripts/**' ],
},
Expand All @@ -133,14 +125,9 @@ function extensionModules( mode, target ) {
onEnd: {
archive: [
{
source: path.join(
targetPath,
'sidebar',
'plugin'
),
source: path.join( targetPath, 'plugin' ),
destination: path.join(
targetPath,
'sidebar',
'plugin.zip'
),
},
Expand Down