Skip to content

Commit 04fa4be

Browse files
committed
Removing NormalModuleReplacementPlugin in favor of a boring alias
1 parent dc49b90 commit 04fa4be

File tree

9 files changed

+16
-59
lines changed

9 files changed

+16
-59
lines changed
File renamed without changes.

dist/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var _stimulus = require("stimulus");
1717

1818
var _webpackHelpers = require("stimulus/webpack-helpers");
1919

20-
var _controllersPlaceholder = _interopRequireDefault(require("./webpack/loader!../controllers-placeholder.json"));
20+
var _controllers = _interopRequireDefault(require("./webpack/loader!@symfony/stimulus-bridge/controllers.json"));
2121

2222
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
2323

@@ -32,21 +32,21 @@ function startStimulusApp(context) {
3232
}
3333

3434
var _loop = function _loop(_controllerName) {
35-
if (!_controllersPlaceholder["default"].hasOwnProperty(_controllerName)) {
35+
if (!_controllers["default"].hasOwnProperty(_controllerName)) {
3636
controllerName = _controllerName;
3737
return "continue";
3838
}
3939

40-
_controllersPlaceholder["default"][_controllerName].then(function (module) {
40+
_controllers["default"][_controllerName].then(function (module) {
4141
// Normalize the controller name: remove the initial @ and use Stimulus format
42-
_controllerName = _controllerName.substr(1).replace(/_/g, "-").replace(/\//g, "--");
42+
_controllerName = _controllerName.substr(1).replace(/_/g, '-').replace(/\//g, '--');
4343
application.register(_controllerName, module["default"]);
4444
});
4545

4646
controllerName = _controllerName;
4747
};
4848

49-
for (var controllerName in _controllersPlaceholder["default"]) {
49+
for (var controllerName in _controllers["default"]) {
5050
var _ret = _loop(controllerName);
5151

5252
if (_ret === "continue") continue;

dist/webpack/create-controllers-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function createControllersModule(config) {
1313
var autoImportContents = '';
1414

1515
if ('undefined' !== typeof config['placeholder']) {
16-
throw new Error('Your controllers.json file was not configured. Did you add the Webpack plugin created by create-controllers-module.js?');
16+
throw new Error('Your controllers.json file was not found. Be sure to add a Webpack alias from "@symfony/stimulus-bridge/controllers.json" to *your* controllers.json file.');
1717
}
1818

1919
if ('undefined' === typeof config['controllers']) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
"src/",
4040
"dist/",
4141
"webpack-helper.js",
42-
"controllers-placeholder.json"
42+
"controllers.json"
4343
]
4444
}

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
import { Application } from 'stimulus';
1313
import { definitionsFromContext } from 'stimulus/webpack-helpers';
1414

15-
// this import is be replaced by the NormalModuleReplacementPlugin
16-
// to point to the real controllers.json file
17-
// See create-controllers-module.js
18-
import symfonyControllers from './webpack/loader!../controllers-placeholder.json';
15+
// The @symfony/stimulus-bridge/controllers.json should be changed
16+
// to point to the real controllers.json file via a Webpack alias
17+
import symfonyControllers from './webpack/loader!@symfony/stimulus-bridge/controllers.json';
1918

2019
export function startStimulusApp(context) {
2120
const application = Application.start();

src/webpack/create-controllers-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function createControllersModule(config) {
1515

1616
if ('undefined' !== typeof config['placeholder']) {
1717
throw new Error(
18-
'Your controllers.json file was not configured. Did you add the Webpack plugin created by create-controllers-module.js?'
18+
'Your controllers.json file was not found. Be sure to add a Webpack alias from "@symfony/stimulus-bridge/controllers.json" to *your* controllers.json file.'
1919
);
2020
}
2121

src/webpack/plugin.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/webpack.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
const path = require('path');
18-
const createStimulusBridgePlugin = require('../src/webpack/plugin');
1918

2019
module.exports = {
2120
target: 'node',
@@ -27,5 +26,9 @@ module.exports = {
2726
path: path.resolve(__dirname, 'dist'),
2827
libraryTarget: 'commonjs2',
2928
},
30-
plugins: [createStimulusBridgePlugin(path.resolve(__dirname, './controllers.json'))],
29+
resolve: {
30+
alias: {
31+
'@symfony/stimulus-bridge/controllers.json': path.resolve(__dirname, './controllers.json'),
32+
},
33+
},
3134
};

test/webpack/plugin.test.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)