silverstripe / webpack-config

Reusable webpack bundle declarations for Silverstripe modules
BSD 3-Clause "New" or "Revised" License
16 stars 9 forks source link

Add support for windows dirs and woff2 #24

Closed altwohill closed 6 years ago

altwohill commented 6 years ago

Currently, any fonts loaded on windows file systems cause an error

You may need an appropriate loader to handle this file type.

This is because the regex checking assumes a unix directory separator.

Also adjusted file loader to match .woff and .woff2

dhensby commented 6 years ago

@maxime-rainville is this ready?

NightJar commented 6 years ago

composer.json:

    "require": {
        "php": ">=5.6.0",
        "silverstripe/recipe-plugin": "^1.2",
        "silverstripe/recipe-cms": "4.2.x-dev",
        "silverstripe-themes/simple": "~3.2.0"
    },

then: cd vendor/silverstripe/admin && yarn First, a control.

$ yarn info '@silverstripe/webpack-config' | grep version:
  version: '0.9.0',
$ grep -rn '/fonts' node_modules/@silverstripe/webpack-config/
node_modules/@silverstripe/webpack-config/css/modules.js:109:        exclude: /fonts\/([\w_-]+)\.svg$/,
node_modules/@silverstripe/webpack-config/css/modules.js:117:        test: /fonts\/([\w_-]+)\.(woff|eot|ttf|svg)$/,
node_modules/@silverstripe/webpack-config/js/modules.js:32:        exclude: /fonts\/([\w_-]+)\.svg$/,
$ NODE_ENV=production node_modules/.bin/webpack -p --bail --progress
[...]
ERROR in ./client/src/font/fonts/silverstripe.ttf
        Module parse failed: [...]client\src\font\fonts\silverstripe.ttf Unexpected character '' (1:0)
        You may need an appropriate loader to handle this file type.
[...]

Error. Neat. Now lets apply the patch.

$ grep -rn '/fonts' node_modules/@silverstripe/webpack-config/
node_modules/@silverstripe/webpack-config/css/modules.js:109:        exclude: /fonts[\/\\]([\w_-]+)\.svg$/,
node_modules/@silverstripe/webpack-config/css/modules.js:117:        test: /fonts[\/\\]([\w_-]+)\.(woff|eot|ttf|svg)$/,
node_modules/@silverstripe/webpack-config/js/modules.js:32:        exclude: /fonts[\/\\]([\w_-]+)\.svg$/,

modify the content of yarn build because we don't want to update dependencies first, and also modify the commands appropriately for the shell.

$ node_modules/.bin/eslint client/src/ && node_modules/.bin/sass-lint -v && node_modules/.bin/jest && NODE_ENV=development node_modules/.bin/webpack -p --bail --progress

C:\Users\dwagstaff\work\adminbuild\vendor\silverstripe\admin\client\src\boot\apollo\buildNetworkComponents.js
  18:7  warning  Unexpected console statement  no-console

✖ 1 problem (0 errors, 1 warning)

client/src/styles/_fonts.scss
  17:31  warning  !important not allowed  no-important
  18:22  warning  !important not allowed  no-important
  19:23  warning  !important not allowed  no-important
  20:24  warning  !important not allowed  no-important
  21:24  warning  !important not allowed  no-important

✖ 5 problems (0 errors, 5 warnings)

 PASS  client\src\components\DateField\tests\DateField-test.js
 PASS  client\src\components\DatetimeField\tests\DatetimeField-test.js
 PASS  client\src\components\FieldHolder\tests\FieldHolder-test.js
 PASS  client\src\components\TreeDropdownField\tests\TreeDropdownField-test.js
 PASS  client\src\components\FormBuilder\tests\FormBuilder-test.js
 PASS  client\src\containers\FormBuilderLoader\tests\createIdentifier-test.js
 PASS  client\src\lib\tests\Backend-test.js
 PASS  client\src\boot\tests\BootRoutes-test.js
 PASS  client\src\lib\dependency-injection\tests\ApolloGraphqlScaffoldingContainer-test.js
 PASS  client\src\containers\InsertLinkModal\tests\InsertLinkModal-test.js
 PASS  client\src\lib\dependency-injection\tests\MiddlewareRegistry-test.js
 PASS  client\src\components\GridFieldActions\tests\GridFieldActions-test.js
 PASS  client\src\lib\dependency-injection\tests\Container-test.js
 PASS  client\src\components\UsedOnTable\tests\UsedOnTable-test.js
 PASS  client\src\lib\dependency-injection\tests\loadComponent-test.js
  ● Console

    console.error node_modules\react\node_modules\fbjs\lib\warning.js:36
      Warning: Failed prop type: The prop `store` is marked as required in `Provider`, but its value is `undefined`.
          in Provider (created by withInjector(
          LegacyLoader
        ))
          in withInjector(
          LegacyLoader
        )
    console.error node_modules\react\node_modules\fbjs\lib\warning.js:36
      Warning: Failed childContext type: The childContext `store` is marked as required in `Provider`, but its value is `undefined`.
          in Provider (created by withInjector(
          LegacyLoader
        ))
          in div (created by ApolloProvider)
          in ApolloProvider (created by withInjector(
          LegacyLoader
        ))
          in withInjector(
          LegacyLoader
        )

 PASS  client\src\components\TreeDropdownField\tests\TreeDropdownFieldUtils-test.js
 PASS  client\src\components\FormBuilderModal\tests\FormBuilderModal-test.js
 PASS  client\src\components\CheckboxSetField\tests\CheckboxSetField-test.js
 PASS  client\src\components\LookupField\tests\LookupField-test.js
 PASS  client\src\components\GridField\tests\GridField-test.js
 PASS  client\src\components\TreeDropdownField\tests\TreeDropdownFieldMenu-test.js
 PASS  client\src\lib\tests\Validator-test.js
 PASS  client\src\components\OptionsetField\tests\OptionsetField-test.js
 PASS  client\src\components\TextField\tests\TextField-test.js
 PASS  client\src\components\TimeField\tests\TimeField-test.js
 PASS  client\src\components\Badge\tests\Badge-test.js
 PASS  client\src\components\Breadcrumb\tests\breadcrumb-test.js
 PASS  client\src\lib\dependency-injection\tests\inject-test.js
 PASS  client\src\lib\dependency-injection\tests\ApolloGraphqlManager-test.js
 PASS  client\src\state\records\tests\RecordsReducer-test.js
 PASS  client\src\lib\dependency-injection\tests\FormStateManager-test.js
 PASS  client\src\lib\dependency-injection\tests\FormContainer-test.js
 PASS  client\src\lib\tests\castStringToElement-test.js
 PASS  client\src\components\TinymceInlineToolbar\tests\TinymceInlineToolbar-test.js
 PASS  client\src\lib\dependency-injection\tests\InjectorContainer-test.js
 PASS  client\src\lib\tests\ReactRouteRegister-test.js
 PASS  client\src\lib\dependency-injection\tests\BaseContainer-test.js
 PASS  client\src\state\schema\tests\SchemaReducer-test.js
 PASS  client\src\lib\tests\DataFormat-test.js
 PASS  client\src\lib\dependency-injection\tests\ComponentContainer-test.js
 PASS  client\src\lib\tests\TinyMCEActionRegistrar-test.js
 PASS  client\src\lib\tests\formatWrittenNumber-test.js
 PASS  client\src\lib\dependency-injection\tests\ReducerContainer-test.js
 PASS  client\src\lib\tests\ShortcodeSerialiser-test.js
 PASS  client\src\lib\dependency-injection\tests\FormValidationManager-test.js
 PASS  client\src\lib\tests\router-test.js

Test Suites: 46 passed, 46 total
Tests:       361 passed, 361 total
Snapshots:   0 total
Time:        95.313s
Ran all test suites.
[2] Hash: b7ef55509e5718a600ba2dab19ca1b604e72904851a69fe4089dbc447d63
Version: webpack 2.7.0
Child js:
    Hash: b7ef55509e5718a600ba
    Time: 54722ms
                                Asset       Size  Chunks                    Chunk Names
                     js/bundle.js.map    2.64 MB       0  [emitted]         bundle
                         js/bundle.js     521 kB       0  [emitted]  [big]  bundle
           js/TinyMCE_sslink-email.js    2.51 kB       2  [emitted]         TinyMCE_sslink-email
                 js/browserWarning.js    3.07 kB       3  [emitted]         browserWarning
                 js/TinyMCE_sslink.js       6 kB       4  [emitted]         TinyMCE_sslink
                      js/leaktools.js  864 bytes       5  [emitted]         leaktools
               js/MemberImportForm.js  535 bytes       6  [emitted]         MemberImportForm
               js/LeftAndMain.Ping.js  741 bytes       7  [emitted]         LeftAndMain.Ping
                         js/vendor.js    2.18 MB       8  [emitted]  [big]  vendor
        js/TinyMCE_sslink-external.js    2.12 kB       1  [emitted]         TinyMCE_sslink-external
    js/TinyMCE_sslink-external.js.map    11.9 kB       1  [emitted]         TinyMCE_sslink-external
       js/TinyMCE_sslink-email.js.map    14.1 kB       2  [emitted]         TinyMCE_sslink-email
             js/browserWarning.js.map    12.8 kB       3  [emitted]         browserWarning
             js/TinyMCE_sslink.js.map    33.9 kB       4  [emitted]         TinyMCE_sslink
                  js/leaktools.js.map    4.26 kB       5  [emitted]         leaktools
           js/MemberImportForm.js.map    2.37 kB       6  [emitted]         MemberImportForm
           js/LeftAndMain.Ping.js.map    4.62 kB       7  [emitted]         LeftAndMain.Ping
                     js/vendor.js.map    12.4 MB       8  [emitted]         vendor
    [./client/src/bundles/bundle.js] ./client/src/bundles/bundle.js 4.97 kB {0} [built]
    [./client/src/bundles/vendor.js] ./client/src/bundles/vendor.js 2.31 kB {8} [built]
    [./client/src/legacy/LeftAndMain.Ping.js] ./client/src/legacy/LeftAndMain.Ping.js 1.24 kB {7} [built]
    [./client/src/legacy/LeftAndMain.js] ./client/src/legacy/LeftAndMain.js 32 kB {0} [built]
    [./client/src/legacy/MemberImportForm.js] ./client/src/legacy/MemberImportForm.js 614 bytes {6} [built]
    [./client/src/legacy/TinyMCE_sslink-email.js] ./client/src/legacy/TinyMCE_sslink-email.js 4.4 kB {2} [built]
    [./client/src/legacy/TinyMCE_sslink-external.js] ./client/src/legacy/TinyMCE_sslink-external.js 3.6 kB {1} [built]
    [./client/src/legacy/TinyMCE_sslink.js] ./client/src/legacy/TinyMCE_sslink.js 3.96 kB {4} [built]
    [./client/src/legacy/leaktools.js] ./client/src/legacy/leaktools.js 1.38 kB {5} [built]
    [./client/src/legacy/ssui.core.js] ./client/src/legacy/ssui.core.js 5.57 kB {0} [built]
    [./client/src/lib/browserWarning.js] ./client/src/lib/browserWarning.js 500 bytes {3} [built]
    [./node_modules/script-loader/index.js!./thirdparty/jquery/jquery.js] ./~/script-loader!./thirdparty/jquery/jquery.js 340 bytes {8} [built]
    [./thirdparty/jquery-cookie/jquery.cookie.js] ./thirdparty/jquery-cookie/jquery.cookie.js 4.38 kB {8} [built]
    [./thirdparty/jquery-entwine/dist/jquery.entwine-dist.js] ./thirdparty/jquery-entwine/dist/jquery.entwine-dist.js 64.8 kB {8} [built]
    [./thirdparty/jquery-ui/jquery-ui.js] ./thirdparty/jquery-ui/jquery-ui.js 373 kB {8} [built]
        + 1799 hidden modules
Child i18n:
    Hash: 2dab19ca1b604e729048
    Time: 3566ms
             Asset     Size  Chunks             Chunk Names
        js/i18n.js  3.18 kB       0  [emitted]  i18n
    js/i18n.js.map  22.3 kB       0  [emitted]  i18n
    [./client/src/i18n.js] ./client/src/i18n.js 5.12 kB {0} [built]
Child css:
    Hash: 51a69fe4089dbc447d63
    Time: 63548ms
                                      Asset       Size  Chunks                    Chunk Names
                          styles/editor.css  169 bytes    1, 1  [emitted]         editor, editor
            images/sprite-sprites-32x32.png    21.8 kB          [emitted]
                     fonts/silverstripe.svg      68 kB          [emitted]
                     fonts/silverstripe.ttf    25.3 kB          [emitted]
                    fonts/silverstripe.woff    18.3 kB          [emitted]
       images/sitetree_ss_default_icons.png    21.6 kB          [emitted]
    images/sitetree_ss_default_icons@2x.png    51.4 kB          [emitted]
              images/cms_content_header.png    14.6 kB          [emitted]
                 styles/GridField_print.css  398 bytes    0, 0  [emitted]         GridField_print, GridField_print
                     fonts/silverstripe.eot    25.4 kB          [emitted]
                          styles/bundle.css     522 kB    2, 2  [emitted]  [big]  bundle, bundle
                 styles/browser-warning.css    27.4 kB    3, 3  [emitted]         browser-warning, browser-warning
             styles/GridField_print.css.map    2.02 kB    0, 0  [emitted]         GridField_print, GridField_print
                      styles/editor.css.map  936 bytes    1, 1  [emitted]         editor, editor
                      styles/bundle.css.map     639 kB    2, 2  [emitted]         bundle, bundle
             styles/browser-warning.css.map    9.72 kB    3, 3  [emitted]         browser-warning, browser-warning
                   images/chosen-sprite.png  538 bytes          [emitted]
                images/chosen-sprite@2x.png  738 bytes          [emitted]
       [0] ./client/src/styles/browser-warning.scss 41 bytes {3} [built]
       [1] ./client/src/styles/bundle.scss 41 bytes {2} [built]
       [2] ./client/src/styles/editor.scss 41 bytes {1} [built]
       [3] ./client/src/styles/legacy/GridField_print.scss 41 bytes {0} [built]
    Child extract-text-webpack-plugin:
           [0] ./~/css-loader/lib/css-base.js 2.26 kB {0} [built]
           [1] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./~/postcss-loader/lib?{"sourceMap":true,"plugins":[null]}!./~/resolve-url-loader!./~/sass-loader/lib/loader.js?{"includePaths":["C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles"],"sourceMap":true}!./client/src/styles/editor.scss 1.4 kB {0} [built]
    Child extract-text-webpack-plugin:
           [0] ./~/css-loader/lib/css-base.js 2.26 kB {0} [built]
           [1] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./~/postcss-loader/lib?{"sourceMap":true,"plugins":[null]}!./~/resolve-url-loader!./~/sass-loader/lib/loader.js?{"includePaths":["C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles"],"sourceMap":true}!./client/src/styles/legacy/GridField_print.scss 2.33 kB {0} [built]
    Child extract-text-webpack-plugin:
           [0] ./~/css-loader/lib/css-base.js 2.26 kB {0} [built]
           [1] ./~/css-loader/lib/url/escape.js 448 bytes {0} [built]
           [2] ./client/src/images/chrome.png 2.38 kB {0} [built]
           [3] ./client/src/images/chrome.svg 3.04 kB {0} [built]
           [4] ./client/src/images/firefox.png 2.34 kB {0} [built]
           [5] ./client/src/images/firefox.svg 3.6 kB {0} [built]
           [6] ./client/src/images/ie.png 2.37 kB {0} [built]
           [7] ./client/src/images/ie.svg 5.5 kB {0} [built]
           [8] ./client/src/images/ss-logo.png 4.19 kB {0} [built]
           [9] ./client/src/images/ss-logo.svg 2.92 kB {0} [built]
          [10] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./~/postcss-loader/lib?{"sourceMap":true,"plugins":[null]}!./~/resolve-url-loader!./~/sass-loader/lib/loader.js?{"includePaths":["C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles"],"sourceMap":true}!./client/src/styles/browser-warning.scss 11.3 kB {0} [built]
    Child extract-text-webpack-plugin:
                                          Asset     Size  Chunks             Chunk Names
                images/sprite-sprites-32x32.png  21.8 kB          [emitted]
                         fonts/silverstripe.eot  25.4 kB          [emitted]
                         fonts/silverstripe.svg    68 kB          [emitted]
                         fonts/silverstripe.ttf  25.3 kB          [emitted]
                        fonts/silverstripe.woff  18.3 kB          [emitted]
           images/sitetree_ss_default_icons.png  21.6 kB          [emitted]
        images/sitetree_ss_default_icons@2x.png  51.4 kB          [emitted]
                  images/cms_content_header.png  14.6 kB          [emitted]
           [0] ./client/src/images/sprites/sprite-sprites-32x32.png 77 bytes {0} [built]
           [2] ./client/src/images/network-save.gif 2.36 kB {0} [built]
           [3] ./client/src/images/spinner.gif 2.98 kB {0} [built]
           [4] ./client/src/images/throbber.gif 2.51 kB {0} [built]
           [6] ./~/css-loader/lib/url/escape.js 448 bytes {0} [built]
           [7] ./client/src/font/fonts/silverstripe.eot 68 bytes {0} [built]
          [12] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./~/chosen-js/chosen.css 24.3 kB {0} [built]
          [13] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./~/react-select/dist/react-select.css 20 kB {0} [built]
          [14] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./thirdparty/jquery-notice/jquery.notice.css 1.8 kB {0} [built]
          [22] ./client/src/images/sitetree_ss_default_icons.png 82 bytes {0} [built]
          [26] ./client/src/images/sprites/sprite-sprites-64x64.png 8.07 kB {0} [built]
          [27] ./client/src/images/sticky-toggle-off.png 477 bytes {0} [built]
          [28] ./client/src/images/sticky-toggle-on.png 521 bytes {0} [built]
          [29] ./client/src/images/textures/cms_content_header.png 75 bytes {0} [built]
          [30] ./~/css-loader?{"sourceMap":true,"minimize":true,"discardComments":true}!./~/postcss-loader/lib?{"sourceMap":true,"plugins":[null]}!./~/resolve-url-loader!./~/sass-loader/lib/loader.js?{"includePaths":["C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles","C://Users//dwagstaff//work//adminbuild//vendor//silverstripe//admin//client//src//styles"],"sourceMap":true}!./client/src/styles/bundle.scss 979 kB {0} [built]
            + 29 hidden modules

PASS albeit with warnings, but a successful compilation none the less.

NightJar commented 6 years ago

node_modules/.bin/start-storybook -p 6006 now also works :) (aka yarn pattern-lib) ... after https://github.com/silverstripe/silverstripe-admin/issues/465#issuecomment-376305218

TL,DR: Merge :)

Resolves:

21

https://github.com/silverstripe/silverstripe-admin/issues/495 https://github.com/silverstripe/silverstripe-admin/issues/465

Please don't forget to tag release :)

maxime-rainville commented 6 years ago

@NightJar We got something else to merge into this repo today. I'll do a tag release then.