France's Socialist government has enshrined in law a defense strategy based on moving closer to the Atlantic Alliance to counter what it depicts as a growing Soviet military threat.

The new strategy is the result of a gradual evolution in French attitudes on national defense since the days of Gen. Charles de Gaulle. The emphasis put by the founder of France's Fifth Republic on an independent nuclear force, ready to defend the country against any potential aggressor, has now been combined with an explicit acknowledgment that the security of Western Europe is closely bound up with that of the United States.

The five-year defense program adopted by the National Assembly yesterday is significant because it represents the most authoritative statement of France's military strategy since the Socialists came to power in May 1981. It formally incorporates many of the concerns voiced by President Francois Mitterrand about the buildup of Soviet SS20 nuclear missiles and warns that France cannot remain "indifferent" to attempts by Moscow to decouple Europe from the United States.

The explicit mention of the Soviet Union as the principal danger to France's security drew a protest from the Communists, who serve as junior partners in the Socialist-led coalition. The Communists, who abstained from voting on this particular section of the bill, are virtually alone in clinging to the original Gaullist notion of a nuclear deterrent aimed impartially at "all points of the compass."

De Gaulle withdrew France from the integrated military command of the North Atlantic Treaty Organization in 1966 and obliged NATO to move its headquarters from Paris to Brussels. France remained a member of NATO, however, and during the next 15 years de Gaulle's absolutist conception of national independence was softened as French strategists began to admit that a Soviet attack elsewhere in Europe might also pose a threat to France.

In the view of French and American military analysts here, the present Socialist government has gone one step further by coordinating its defense plans more closely with other NATO countries while retaining the principle of independent command. NATO's ministerial council is scheduled to meet in Paris next month for the first time in several years.

"The French warnings about Soviet attempts to decouple Western Europe from the United States are important because they constitute the first implicit recognition by the French of the importance of the American nuclear umbrella. "This is a real change in French policy," remarked an American expert on military affairs, who asked not to be named.

The new defense law, which runs from 1984 to 1988, contains several elements designed to increase the effectiveness of France's contribution to NATO. One of the most important is the creation of a rapid deployment force, built up around a helicopter antitank unit, that could presumably be committed to forward positions in Central Europe at a time of war.

Defense Minister Charles Hernu has promised that French units already stationed in West Germany will be kept at their present level--and that their firepower and mobility will be increased. Overall cuts in the armed forces will be limited to 35,000 men, or 5 percent of total defense personnel. This is considerably less than the reduction originally discussed.

The centerpiece of France's defense system will remain its strategic nuclear deterrent or force de frappe. Two new nuclear submarines with multiple-warhead missiles are due to come into service during the next decade, and the Mirage bomber force will receive new medium-range missiles. The Pluton tactical nuclear missile, which has a range of 72 miles, will be replaced by the Hades with a range of 210 miles.

This week's debate in the National Assembly underlined the political consensus that exists in France on defense matters. The harsh criticisms of the right-wing opposition members were directed not so much at the Socialist Party's plans, but at the government's ability to carry them out during a time of economic austerity. The main focus of attack was what was said to be the unrealistic assumption of an annual inflation rate of 5 percent.

The defense debate was accompanied by a good deal of self-congratulation that France has managed to escape what one speaker described as the "moral crisis" of pacifism or isolationism afflicting other NATO countries. Even the Communists feel obliged to support the concept of an independent French nuclear deterrent, which is identified by public opinion here with national sovereignty.

Closing the debate, Hernu was able to boast: "I had the feeling that the opposition was a bit annoyed at being in agreement with me . . . . As far is a defense is concerned, there is a continuity which transcends changes of political power."

Most French military analysts seem to agree that had de Gaulle been alive today, he would follow essentially the same policy as Mitterrand. The attempt to pursue a totally independent defense strategy, it is now acknowledged, was only viable at a time when the military balance of power in Europe favored the United States. Now that it has shifted, the French have had to take sides.

Pierre Lelouche, director of studies at the French Institute for International Relations, suggested that West Germany provides the key to understanding de Gaulle's policy.

"Under de Gaulle, the French feared that West Germany had become too close to the United States. There's an opposite concern now. Mitterrand is working to preserve the status quo in Germany as a buffer zone against the Soviet Union. It is only under these conditions that France can preserve its national independence," he said.

NATO military planners now openly assume that France would commit its forces early, in the event of a Soviet attack on Western Europe.

Short of war breaking out, however, it seems unlikely that France will rejoin the command structure of NATO. Such a move could undermine the basis of the present national consensus on defense and give the Soviets greater justification for demanding the inclusion of French forces in arms-reduction talks in Europe.

The new defense law stresses that France, as "a founder member of the Atlantic Alliance," remains "a faithful partner of this defensive grouping of sovereign nations."

"France intends to be able to engage itself on the side of its partners in the Atlantic Alliance if they are victims of aggression," the law notes. It adds, however, that France "retains total freedom of evaluation and decision as to the use of its forces in the event of crisis or conflict."