Skip to content

Commit 8561244

Browse files
committed
Improve CHANGELOG, add tests for Babel and PostCSS with ESM configs
1 parent 12cffdb commit 8561244

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ can adopt modern async APIs from the ecosystem without hacks**.
6262
// After (ESM)
6363
import path from 'path';
6464
```
65+
Similarly, `require.resolve()` becomes `import.meta.resolve()`:
66+
```js
67+
// Before (CJS)
68+
options.implementation = require.resolve('sass-embedded');
69+
70+
// After (ESM)
71+
options.implementation = import.meta.resolve('sass-embedded');
72+
```
6573
If you need to require a CJS-only package, use `createRequire`:
6674
```js
6775
import { createRequire } from 'module';
@@ -84,6 +92,16 @@ can adopt modern async APIs from the ecosystem without hacks**.
8492
};
8593
```
8694
95+
* With `"type": "module"`, webpack enables
96+
[`resolve.fullySpecified`](https://webpack.js.org/configuration/module/#resolvefullyspecified)
97+
by default. This means **file extensions are now required** in some imports that previously
98+
worked without them:
99+
- **Relative imports**: `import('./shelter_join')``import('./shelter_join.js')`
100+
- **Deep package imports** from packages that do not have an `"exports"` field in their
101+
`package.json` (e.g. `licia`, `jquery-ui`, `Hinclude`):
102+
`import delegate from 'licia/delegate'``import delegate from 'licia/delegate.js'`
103+
`import 'jquery-ui/ui/widgets/progressbar'``import 'jquery-ui/ui/widgets/progressbar.js'`
104+
87105
* The package `"exports"` field is now restrictive: only `"@symfony/webpack-encore"` and
88106
`"@symfony/webpack-encore/lib/plugins/plugin-priorities.js"` are exposed as public entry points.
89107
If you were importing other internal modules directly, those imports will no longer work.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class Encore {
408408
* Or:
409409
*
410410
* ```
411-
* const nodeExternals = require('webpack-node-externals');
411+
* import nodeExternals from 'webpack-node-externals';
412412
*
413413
* Encore.addExternals(
414414
* nodeExternals()

test/functional.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,51 @@ module.exports = {
10861086
});
10871087
});
10881088

1089+
it('PostCSS works when enabled (ESM config)', function(done) {
1090+
const appDir = testSetup.createTestAppDir();
1091+
1092+
// Enable ESM so that postcss.config.js is treated as an ES module
1093+
fs.writeFileSync(
1094+
path.join(appDir, 'package.json'),
1095+
JSON.stringify({ private: true, type: 'module' })
1096+
);
1097+
1098+
fs.writeFileSync(
1099+
path.join(appDir, 'postcss.config.js'),
1100+
`
1101+
export default {
1102+
plugins: {
1103+
'autoprefixer': {},
1104+
}
1105+
}
1106+
`
1107+
);
1108+
1109+
// Force very old Safari to ensure that autoprefixer will prefix `backdrop-filter`
1110+
fs.writeFileSync(path.join(appDir, '.browserslistrc'), 'Safari 9');
1111+
1112+
const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev');
1113+
config.enableSingleRuntimeChunk();
1114+
config.setPublicPath('/build');
1115+
config.addStyleEntry('styles', ['./css/imports_autoprefixer.css']);
1116+
config.addStyleEntry('postcss', './css/postcss_extension.postcss');
1117+
config.enablePostCssLoader();
1118+
1119+
testSetup.runWebpack(config, (webpackAssert) => {
1120+
webpackAssert.assertOutputFileContains(
1121+
'styles.css',
1122+
'-webkit-backdrop-filter'
1123+
);
1124+
1125+
webpackAssert.assertOutputFileContains(
1126+
'postcss.css',
1127+
'-webkit-backdrop-filter'
1128+
);
1129+
1130+
done();
1131+
});
1132+
});
1133+
10891134
it('less processes when enabled', function(done) {
10901135
const config = createWebpackConfig('www/build', 'dev');
10911136
config.setPublicPath('/build');
@@ -1174,6 +1219,46 @@ module.exports = {
11741219
});
11751220
});
11761221

1222+
it('Babel can be configured via babel.config.js (ESM)', function(done) {
1223+
const appDir = testSetup.createTestAppDir();
1224+
1225+
// Enable ESM so that babel.config.js is treated as an ES module
1226+
fs.writeFileSync(
1227+
path.join(appDir, 'package.json'),
1228+
JSON.stringify({ private: true, type: 'module' })
1229+
);
1230+
1231+
fs.writeFileSync(
1232+
path.join(appDir, 'babel.config.js'),
1233+
`
1234+
export default {
1235+
presets: [
1236+
["@babel/preset-env", {
1237+
targets: {
1238+
chrome: 52
1239+
}
1240+
}]
1241+
]
1242+
}
1243+
`
1244+
);
1245+
1246+
const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev');
1247+
config.enableSingleRuntimeChunk();
1248+
config.setPublicPath('/build');
1249+
config.addEntry('main', './js/class-syntax');
1250+
1251+
testSetup.runWebpack(config, (webpackAssert) => {
1252+
// chrome 52 supports class, so it's not transpiled
1253+
webpackAssert.assertOutputFileContains(
1254+
'main.js',
1255+
'class A {}'
1256+
);
1257+
1258+
done();
1259+
});
1260+
});
1261+
11771262
it('Babel can be configured via package.json browserlist', function(done) {
11781263
const cwd = process.cwd();
11791264

0 commit comments

Comments
 (0)