webpack-encore 및 babel과 함께 사용하는 Symfony 5 프로젝트가 있습니다.
처음에는 webpack.config.js에서 babel을 활성화했습니다.
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
encore를 통해 생성 된 구성을 덤프 한 후이 babel.config.js 파일을 만든 것 같습니다.
module.exports = {
'presets': [
[
'@babel/preset-env',
{
'modules': 'auto', # this line was set to false, which made the whole thing bug
'targets': {
node: 'current',
},
'useBuiltIns': 'usage',
'corejs': 3,
},
],
'@babel/react',
],
'plugins': [
'@babel/plugin-syntax-dynamic-import',
],
};
각 옵션을 시도한 후 babel 구성 파일없이 Jest를 시작했지만
.configureBabelPresetEnv((config) => {
config.modules = 'auto';
config.useBuiltIns = 'usage';
config.corejs = 3;
})
그러나 그로 인해 jest는 실행되지 않습니다.
FAIL assets/jest/Domain/Events/EventScheduler.test.js
● Test suite failed to run
EventScheduler.test.js:1
import EventScheduler from '../../../js/Domain/Events/EventScheduler';
^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Runtime._execModule (node_modules/jest-runtime/build/index.js:1166:56)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.671 s
Ran all test suites.
Jest가 webpack의 설정에서 설정을 가져 오지 않았다고 제안합니다.
webpack을 jest에 연결하려고 시도하면서 공식 가이드를 따르려고했습니다. https://jestjs.io/docs/en/webpack 그러나 제안 된 구성 :
module.exports = {
module: {
loaders: [
{exclude: ['node_modules'], loader: 'babel', test: /\.jsx?$/},
{loader: 'style-loader!css-loader', test: /\.css$/},
{loader: 'url-loader', test: /\.gif$/},
{loader: 'file-loader', test: /\.(ttf|eot|svg)$/},
],
},
resolve: {
alias: {
config$: './configs/app-config.js',
react: './vendor/react-master',
},
extensions: ['', 'js', 'jsx'],
modules: [
'node_modules',
'bower_components',
'shared',
'/shared/vendor/modules',
],
},
};
webpack에서 오류가 발생합니다.
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { defaultRules?, exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, strictExportPresence?, strictThisContextOnImports?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? }
-> Options affecting the normal modules (`NormalModuleFactory`).
- configuration.resolve.extensions[0] should be an non-empty string.
-> A non-empty string
error Command failed with exit code 1.
지금은 별도의 babel.config.js 파일로 작업하는 것이 있지만 encore로 수행하는 표준 방법이 있습니까?
결국 Encore에서 babel conf를 얻었습니다.
// babel.config.js
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
};
// webpack.config.js
const path = require('path');
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath(path.resolve('./../public/build'))
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.splitEntryChunks()
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader()
.enableReactPreset()
module.exports = Encore.getWebpackConfig();
$ ./node_modules/.bin/jest
PASS assets/js/Modal.test.jsx
✓ scenario de test (35 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.56 s, estimated 2 s
Ran all test suites.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다