Skip to content

Commit

Permalink
Merge pull request #63 from 10up/fix/webpack-asset-modules
Browse files Browse the repository at this point in the history
Fix regex in asset/resources'
  • Loading branch information
nicholasio authored May 22, 2021
2 parents 586fb61 + 2e6031a commit ad7c717
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 36 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-test-projects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: projects builds

on: [pull_request]

jobs:
unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 15.x]

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Setup npm cache
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: build library
run: (cd projects/library && npm run build)
- name: build ts library
run: (cd projects/library-ts && npm run build)
- name: build 10up theme
run: (cd projects/10up-theme && npm run build)
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ Object {
},
},
"externals": Object {
"lodash": "lodash",
"read-pkg": "read-pkg",
"read-pkg-up": "read-pkg-up",
"resolve-bin": "resolve-bin",
"lodash": Object {
"amd": "lodash",
"commonjs": "lodash",
"commonjs2": "lodash",
},
"read-pkg": Object {
"amd": "read-pkg",
"commonjs": "read-pkg",
"commonjs2": "read-pkg",
},
"read-pkg-up": Object {
"amd": "read-pkg-up",
"commonjs": "read-pkg-up",
"commonjs2": "read-pkg-up",
},
"resolve-bin": Object {
"amd": "resolve-bin",
"commonjs": "resolve-bin",
"commonjs2": "resolve-bin",
},
},
"mode": "development",
"module": Object {
Expand Down Expand Up @@ -99,7 +115,7 @@ Object {
],
},
Object {
"test": /\\\\\\.\\{jpg,jpeg,png,gif,svg,eot,ttf,woff,woff2\\}/,
"test": /\\\\\\.\\(woff\\(2\\)\\?\\|ttf\\|eot\\|svg\\|jpg\\|jpeg\\|png\\|giff\\|webp\\)\\(\\\\\\?v=\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\)\\?\\$/,
"type": "asset/resource",
},
],
Expand Down Expand Up @@ -315,9 +331,21 @@ Object {
},
},
"externals": Object {
"read-pkg": "read-pkg",
"read-pkg-up": "read-pkg-up",
"resolve-bin": "resolve-bin",
"read-pkg": Object {
"amd": "read-pkg",
"commonjs": "read-pkg",
"commonjs2": "read-pkg",
},
"read-pkg-up": Object {
"amd": "read-pkg-up",
"commonjs": "read-pkg-up",
"commonjs2": "read-pkg-up",
},
"resolve-bin": Object {
"amd": "resolve-bin",
"commonjs": "resolve-bin",
"commonjs2": "resolve-bin",
},
},
"mode": "development",
"module": Object {
Expand Down Expand Up @@ -348,6 +376,7 @@ Object {
},
],
],
"sourceType": "unambiguous",
},
},
],
Expand Down Expand Up @@ -413,7 +442,7 @@ Object {
],
},
Object {
"test": /\\\\\\.\\{jpg,jpeg,png,gif,svg,eot,ttf,woff,woff2\\}/,
"test": /\\\\\\.\\(woff\\(2\\)\\?\\|ttf\\|eot\\|svg\\|jpg\\|jpeg\\|png\\|giff\\|webp\\)\\(\\\\\\?v=\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\)\\?\\$/,
"type": "asset/resource",
},
],
Expand Down Expand Up @@ -478,9 +507,21 @@ Object {
},
},
"externals": Object {
"read-pkg": "read-pkg",
"read-pkg-up": "read-pkg-up",
"resolve-bin": "resolve-bin",
"read-pkg": Object {
"amd": "read-pkg",
"commonjs": "read-pkg",
"commonjs2": "read-pkg",
},
"read-pkg-up": Object {
"amd": "read-pkg-up",
"commonjs": "read-pkg-up",
"commonjs2": "read-pkg-up",
},
"resolve-bin": Object {
"amd": "resolve-bin",
"commonjs": "resolve-bin",
"commonjs2": "resolve-bin",
},
},
"mode": "development",
"module": Object {
Expand Down Expand Up @@ -511,6 +552,7 @@ Object {
},
],
],
"sourceType": "unambiguous",
},
},
],
Expand Down Expand Up @@ -576,7 +618,7 @@ Object {
],
},
Object {
"test": /\\\\\\.\\{jpg,jpeg,png,gif,svg,eot,ttf,woff,woff2\\}/,
"test": /\\\\\\.\\(woff\\(2\\)\\?\\|ttf\\|eot\\|svg\\|jpg\\|jpeg\\|png\\|giff\\|webp\\)\\(\\\\\\?v=\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\)\\?\\$/,
"type": "asset/resource",
},
],
Expand Down Expand Up @@ -649,10 +691,26 @@ Object {
},
},
"externals": Object {
"lodash": "lodash",
"read-pkg": "read-pkg",
"read-pkg-up": "read-pkg-up",
"resolve-bin": "resolve-bin",
"lodash": Object {
"amd": "lodash",
"commonjs": "lodash",
"commonjs2": "lodash",
},
"read-pkg": Object {
"amd": "read-pkg",
"commonjs": "read-pkg",
"commonjs2": "read-pkg",
},
"read-pkg-up": Object {
"amd": "read-pkg-up",
"commonjs": "read-pkg-up",
"commonjs2": "read-pkg-up",
},
"resolve-bin": Object {
"amd": "resolve-bin",
"commonjs": "resolve-bin",
"commonjs2": "resolve-bin",
},
},
"mode": "development",
"module": Object {
Expand Down Expand Up @@ -683,6 +741,7 @@ Object {
},
],
],
"sourceType": "unambiguous",
},
},
],
Expand Down Expand Up @@ -748,7 +807,7 @@ Object {
],
},
Object {
"test": /\\\\\\.\\{jpg,jpeg,png,gif,svg,eot,ttf,woff,woff2\\}/,
"test": /\\\\\\.\\(woff\\(2\\)\\?\\|ttf\\|eot\\|svg\\|jpg\\|jpeg\\|png\\|giff\\|webp\\)\\(\\\\\\?v=\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\)\\?\\$/,
"type": "asset/resource",
},
],
Expand Down Expand Up @@ -841,6 +900,7 @@ Object {
},
],
],
"sourceType": "unambiguous",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/config/webpack/externals.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = ({ isPackage, packageConfig: { externals } }) => {
if (isPackage) {
return externals.reduce((acc, current) => {
acc[current] = current;
acc[current] = { commonjs: current, commonjs2: current, amd: current };
return acc;
}, {});
}
Expand Down
3 changes: 2 additions & 1 deletion packages/toolkit/config/webpack/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = ({
...(!hasBabelConfig() && {
babelrc: false,
configFile: false,
sourceType: 'unambiguous',
presets: [
[
require.resolve('@10up/babel-preset-default'),
Expand Down Expand Up @@ -96,7 +97,7 @@ module.exports = ({
},
// when in package module only include referenced resources
isPackage && {
test: /\.{jpg,jpeg,png,gif,svg,eot,ttf,woff,woff2}/,
test: /\.(woff(2)?|ttf|eot|svg|jpg|jpeg|png|giff|webp)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
},
].filter(Boolean),
Expand Down
4 changes: 3 additions & 1 deletion packages/toolkit/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ function getJestOverrideConfigFile(suffix) {
const hasEslintignoreConfig = () => hasProjectFile('.eslintignore');

const getDefaultConfig = () => {
const wpMode = getArgFromCLI('--wp');

return {
entry: require(fromConfigRoot('buildfiles.config.js')),
filenames: require(fromConfigRoot('filenames.config.js')),
paths: require(fromConfigRoot('paths.config.js')),
wordpress: true,
wordpress: wpMode !== 'false',
// true by default (if TENUP_NO_EXTERNALS is not set)
// if TENUP_NO_EXTERNALS is truthy then dependecyExternals is false
wpDependencyExternals:
Expand Down
4 changes: 2 additions & 2 deletions projects/10up-theme/assets/js/frontend/frontend.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import foo from './components/bar';

function helloTypeScript(name: string) {
return `Hello ${name}, this is TypeScript!`;
}

document.write(helloTypeScript('10up'));


4 changes: 3 additions & 1 deletion projects/10up-theme/assets/js/shared/shared.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// import foo from './bar'
import Accordion from '@10up/component-accordion';

new Accordion('.test', {});
3 changes: 2 additions & 1 deletion projects/10up-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"dependencies": {
"normalize.css": "^8.0.1",
"prop-types": "^15.7.2"
"prop-types": "^15.7.2",
"@10up/component-accordion": "2.0.1"
},
"@10up/scripts": {
"devURL": "https://my-project.test",
Expand Down
13 changes: 2 additions & 11 deletions projects/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
"author": "10up",
"description": "Accessible accordion component.",
"main": "dist/index.js",
"exports": "./dist/index.modern.js",
"umd:main": "dist/index.umd.js",
"module": "dist/index.module.js",
"source": "src/index.js",
"style": "./dist/index.css",
"types": "./index.d.ts",
"scripts": {
"watch": "concurrently \"npm run build:modern -- --watch\" \"npm run build:umd -- --watch\"",
"build": "npm run build:modern && npm run build:umd",
"build:modern": "10up-toolkit build -f=commonjs",
"build:modern": "10up-toolkit build -f=commonjs --wp=false",
"build:umd": "10up-toolkit build -f=umd -i=src/index.umd.js --name=TenUpAccordion --external=none"
},
"browserslist": [
"> 1%",
"ie >= 11",
"last 2 versions",
"Firefox ESR"
],
"repository": {
"type": "git",
"url": "git+https://github.com/10up/component-accordion.git"
Expand All @@ -39,7 +30,7 @@
"10up-toolkit": "1.0.4",
"concurrently": "^5.3.0"
},
"@10up/scripts": {
"10up-toolkit": {
"libraryName": "TenUpAccordion"
}
}
Binary file added projects/library/src/assets/fonts/MrGeorge.ttf
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions projects/library/src/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
@import url('assets/core.css');

:root {
--primary-font: 'Mr George', Arial, Helvetica, sans-serif;
}

@font-face {
font-family: 'Mr George';
src: url('./assets/fonts/MrGeorgeHeavy.ttf') format('truetype');
font-weight: 900
}

@font-face {
font-family: 'Mr George';
src: url('./assets/fonts/MrGeorge.ttf') format('truetype');
font-weight: 400
}

.accordion-header {
border-bottom: 1px solid #303030;
cursor: pointer;
Expand Down

0 comments on commit ad7c717

Please sign in to comment.